{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Solutions\n",
    "This notebook contains solutions to all the exercises from the Selecting Subsets of Data Series\n",
    "\n",
    "1. [Part 1: Selection with [], .loc and .iloc](#Part-1:-Selection-with-[],-.loc-and-.iloc)\n",
    "1. [Part 2: Boolean Indexing](#Part-2:-Boolean-Indexing)\n",
    "1. [Part 3: Assigning subsets of data](#Part-3:-Assigning-subsets-of-data)\n",
    "1. [Part 4: How NOT to select subsets of data](#Part-4:-How-NOT-to-select-subsets-of-data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Part 1: Selection with `[]`, `.loc` and `.iloc`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DBA Name</th>\n",
       "      <th>Facility Type</th>\n",
       "      <th>Risk</th>\n",
       "      <th>Address</th>\n",
       "      <th>Zip</th>\n",
       "      <th>Inspection Date</th>\n",
       "      <th>Inspection Type</th>\n",
       "      <th>Results</th>\n",
       "      <th>Violations</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>DANY'S TACOS</td>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>2857 S ST LOUIS AVE</td>\n",
       "      <td>60623.0</td>\n",
       "      <td>03/27/2017</td>\n",
       "      <td>License</td>\n",
       "      <td>Fail</td>\n",
       "      <td>16. FOOD PROTECTED DURING STORAGE, PREPARATION...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>BILLY FOOD MARKET INC</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Risk 3 (Low)</td>\n",
       "      <td>3906 W ROOSEVELT RD</td>\n",
       "      <td>60624.0</td>\n",
       "      <td>03/27/2017</td>\n",
       "      <td>License</td>\n",
       "      <td>Not Ready</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>TAQUERIA HACIENDA TAPATIA</td>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>4125 W 26TH ST</td>\n",
       "      <td>60623.0</td>\n",
       "      <td>03/27/2017</td>\n",
       "      <td>License Re-Inspection</td>\n",
       "      <td>Pass</td>\n",
       "      <td>2. FACILITIES TO MAINTAIN PROPER TEMPERATURE -...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>WILD GOOSE BAR &amp; GRILL</td>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>4265 N LINCOLN AVE</td>\n",
       "      <td>60618.0</td>\n",
       "      <td>03/27/2017</td>\n",
       "      <td>Canvass</td>\n",
       "      <td>Fail</td>\n",
       "      <td>16. FOOD PROTECTED DURING STORAGE, PREPARATION...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>PUBLICAN TAVERN K1</td>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>11601 W TOUHY AVE</td>\n",
       "      <td>60666.0</td>\n",
       "      <td>03/27/2017</td>\n",
       "      <td>Canvass</td>\n",
       "      <td>Fail</td>\n",
       "      <td>18. NO EVIDENCE OF RODENT OR INSECT OUTER OPEN...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                    DBA Name Facility Type           Risk  \\\n",
       "0               DANY'S TACOS    Restaurant  Risk 1 (High)   \n",
       "1      BILLY FOOD MARKET INC           NaN   Risk 3 (Low)   \n",
       "2  TAQUERIA HACIENDA TAPATIA    Restaurant  Risk 1 (High)   \n",
       "3     WILD GOOSE BAR & GRILL    Restaurant  Risk 1 (High)   \n",
       "4         PUBLICAN TAVERN K1    Restaurant  Risk 1 (High)   \n",
       "\n",
       "                Address      Zip Inspection Date        Inspection Type  \\\n",
       "0  2857 S ST LOUIS AVE   60623.0      03/27/2017                License   \n",
       "1  3906 W ROOSEVELT RD   60624.0      03/27/2017                License   \n",
       "2       4125 W 26TH ST   60623.0      03/27/2017  License Re-Inspection   \n",
       "3   4265 N LINCOLN AVE   60618.0      03/27/2017                Canvass   \n",
       "4    11601 W TOUHY AVE   60666.0      03/27/2017                Canvass   \n",
       "\n",
       "     Results                                         Violations  \n",
       "0       Fail  16. FOOD PROTECTED DURING STORAGE, PREPARATION...  \n",
       "1  Not Ready                                                NaN  \n",
       "2       Pass  2. FACILITIES TO MAINTAIN PROPER TEMPERATURE -...  \n",
       "3       Fail  16. FOOD PROTECTED DURING STORAGE, PREPARATION...  \n",
       "4       Fail  18. NO EVIDENCE OF RODENT OR INSECT OUTER OPEN...  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('../../data/food_inspections.csv')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 1\n",
    "<span  style=\"color:green; font-size:16px\">The current DataFrame has a simple `RangeIndex`. Let make the **`DBA Name`** column the index to make it more meaningful. Save the result to variable **`df`**.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Facility Type</th>\n",
       "      <th>Risk</th>\n",
       "      <th>Address</th>\n",
       "      <th>Zip</th>\n",
       "      <th>Inspection Date</th>\n",
       "      <th>Inspection Type</th>\n",
       "      <th>Results</th>\n",
       "      <th>Violations</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DBA Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>DANY'S TACOS</th>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>2857 S ST LOUIS AVE</td>\n",
       "      <td>60623.0</td>\n",
       "      <td>03/27/2017</td>\n",
       "      <td>License</td>\n",
       "      <td>Fail</td>\n",
       "      <td>16. FOOD PROTECTED DURING STORAGE, PREPARATION...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BILLY FOOD MARKET INC</th>\n",
       "      <td>NaN</td>\n",
       "      <td>Risk 3 (Low)</td>\n",
       "      <td>3906 W ROOSEVELT RD</td>\n",
       "      <td>60624.0</td>\n",
       "      <td>03/27/2017</td>\n",
       "      <td>License</td>\n",
       "      <td>Not Ready</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TAQUERIA HACIENDA TAPATIA</th>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>4125 W 26TH ST</td>\n",
       "      <td>60623.0</td>\n",
       "      <td>03/27/2017</td>\n",
       "      <td>License Re-Inspection</td>\n",
       "      <td>Pass</td>\n",
       "      <td>2. FACILITIES TO MAINTAIN PROPER TEMPERATURE -...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WILD GOOSE BAR &amp; GRILL</th>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>4265 N LINCOLN AVE</td>\n",
       "      <td>60618.0</td>\n",
       "      <td>03/27/2017</td>\n",
       "      <td>Canvass</td>\n",
       "      <td>Fail</td>\n",
       "      <td>16. FOOD PROTECTED DURING STORAGE, PREPARATION...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PUBLICAN TAVERN K1</th>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>11601 W TOUHY AVE</td>\n",
       "      <td>60666.0</td>\n",
       "      <td>03/27/2017</td>\n",
       "      <td>Canvass</td>\n",
       "      <td>Fail</td>\n",
       "      <td>18. NO EVIDENCE OF RODENT OR INSECT OUTER OPEN...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          Facility Type           Risk               Address  \\\n",
       "DBA Name                                                                       \n",
       "DANY'S TACOS                 Restaurant  Risk 1 (High)  2857 S ST LOUIS AVE    \n",
       "BILLY FOOD MARKET INC               NaN   Risk 3 (Low)  3906 W ROOSEVELT RD    \n",
       "TAQUERIA HACIENDA TAPATIA    Restaurant  Risk 1 (High)       4125 W 26TH ST    \n",
       "WILD GOOSE BAR & GRILL       Restaurant  Risk 1 (High)   4265 N LINCOLN AVE    \n",
       "PUBLICAN TAVERN K1           Restaurant  Risk 1 (High)    11601 W TOUHY AVE    \n",
       "\n",
       "                               Zip Inspection Date        Inspection Type  \\\n",
       "DBA Name                                                                    \n",
       "DANY'S TACOS               60623.0      03/27/2017                License   \n",
       "BILLY FOOD MARKET INC      60624.0      03/27/2017                License   \n",
       "TAQUERIA HACIENDA TAPATIA  60623.0      03/27/2017  License Re-Inspection   \n",
       "WILD GOOSE BAR & GRILL     60618.0      03/27/2017                Canvass   \n",
       "PUBLICAN TAVERN K1         60666.0      03/27/2017                Canvass   \n",
       "\n",
       "                             Results  \\\n",
       "DBA Name                               \n",
       "DANY'S TACOS                    Fail   \n",
       "BILLY FOOD MARKET INC      Not Ready   \n",
       "TAQUERIA HACIENDA TAPATIA       Pass   \n",
       "WILD GOOSE BAR & GRILL          Fail   \n",
       "PUBLICAN TAVERN K1              Fail   \n",
       "\n",
       "                                                                  Violations  \n",
       "DBA Name                                                                      \n",
       "DANY'S TACOS               16. FOOD PROTECTED DURING STORAGE, PREPARATION...  \n",
       "BILLY FOOD MARKET INC                                                    NaN  \n",
       "TAQUERIA HACIENDA TAPATIA  2. FACILITIES TO MAINTAIN PROPER TEMPERATURE -...  \n",
       "WILD GOOSE BAR & GRILL     16. FOOD PROTECTED DURING STORAGE, PREPARATION...  \n",
       "PUBLICAN TAVERN K1         18. NO EVIDENCE OF RODENT OR INSECT OUTER OPEN...  "
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = df.set_index('DBA Name')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 2\n",
    "<span  style=\"color:green; font-size:16px\">Select the **`Risk`** column as a Series with just the indexing operator. Also select it with attribute access.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DBA Name\n",
       "DANY'S TACOS                 Risk 1 (High)\n",
       "BILLY FOOD MARKET INC         Risk 3 (Low)\n",
       "TAQUERIA HACIENDA TAPATIA    Risk 1 (High)\n",
       "WILD GOOSE BAR & GRILL       Risk 1 (High)\n",
       "PUBLICAN TAVERN K1           Risk 1 (High)\n",
       "Name: Risk, dtype: object"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['Risk'].head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DBA Name\n",
       "DANY'S TACOS                 Risk 1 (High)\n",
       "BILLY FOOD MARKET INC         Risk 3 (Low)\n",
       "TAQUERIA HACIENDA TAPATIA    Risk 1 (High)\n",
       "WILD GOOSE BAR & GRILL       Risk 1 (High)\n",
       "PUBLICAN TAVERN K1           Risk 1 (High)\n",
       "Name: Risk, dtype: object"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.Risk.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 3\n",
    "<span  style=\"color:green; font-size:16px\">Select the **`Risk`** and **`Results`** columns</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Risk</th>\n",
       "      <th>Results</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DBA Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>DANY'S TACOS</th>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>Fail</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BILLY FOOD MARKET INC</th>\n",
       "      <td>Risk 3 (Low)</td>\n",
       "      <td>Not Ready</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TAQUERIA HACIENDA TAPATIA</th>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>Pass</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WILD GOOSE BAR &amp; GRILL</th>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>Fail</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PUBLICAN TAVERN K1</th>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>Fail</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    Risk    Results\n",
       "DBA Name                                           \n",
       "DANY'S TACOS               Risk 1 (High)       Fail\n",
       "BILLY FOOD MARKET INC       Risk 3 (Low)  Not Ready\n",
       "TAQUERIA HACIENDA TAPATIA  Risk 1 (High)       Pass\n",
       "WILD GOOSE BAR & GRILL     Risk 1 (High)       Fail\n",
       "PUBLICAN TAVERN K1         Risk 1 (High)       Fail"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['Risk', 'Results']].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 4\n",
    "<span  style=\"color:green; font-size:16px\">Select a single column as a DataFrame</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Zip</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DBA Name</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>DANY'S TACOS</th>\n",
       "      <td>60623.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>BILLY FOOD MARKET INC</th>\n",
       "      <td>60624.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TAQUERIA HACIENDA TAPATIA</th>\n",
       "      <td>60623.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WILD GOOSE BAR &amp; GRILL</th>\n",
       "      <td>60618.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PUBLICAN TAVERN K1</th>\n",
       "      <td>60666.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Zip\n",
       "DBA Name                          \n",
       "DANY'S TACOS               60623.0\n",
       "BILLY FOOD MARKET INC      60624.0\n",
       "TAQUERIA HACIENDA TAPATIA  60623.0\n",
       "WILD GOOSE BAR & GRILL     60618.0\n",
       "PUBLICAN TAVERN K1         60666.0"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['Zip']].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 5\n",
    "<span  style=\"color:green; font-size:16px\">Select the row for the restaurant **`WILD GOOSE BAR & GRILL`**. What object is returned?</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Facility Type                                             Restaurant\n",
       "Risk                                                   Risk 1 (High)\n",
       "Address                                          4265 N LINCOLN AVE \n",
       "Zip                                                            60618\n",
       "Inspection Date                                           03/27/2017\n",
       "Inspection Type                                              Canvass\n",
       "Results                                                         Fail\n",
       "Violations         16. FOOD PROTECTED DURING STORAGE, PREPARATION...\n",
       "Name: WILD GOOSE BAR & GRILL, dtype: object"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['WILD GOOSE BAR & GRILL'] # returns a Series"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 6\n",
    "<span  style=\"color:green; font-size:16px\">Select the rows for the restaurants **`WILD GOOSE BAR & GRILL`** and **`TAQUERIA HACIENDA TAPATIA`** along with columns **`Risk`** and **`Results`**.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Risk</th>\n",
       "      <th>Results</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DBA Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>WILD GOOSE BAR &amp; GRILL</th>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>Fail</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>TAQUERIA HACIENDA TAPATIA</th>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>Pass</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                    Risk Results\n",
       "DBA Name                                        \n",
       "WILD GOOSE BAR & GRILL     Risk 1 (High)    Fail\n",
       "TAQUERIA HACIENDA TAPATIA  Risk 1 (High)    Pass"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[['WILD GOOSE BAR & GRILL', 'TAQUERIA HACIENDA TAPATIA'], ['Risk', 'Results']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 7\n",
    "<span  style=\"color:green; font-size:16px\">What is the risk of restaurant **`SCRUB A DUB`**?</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Risk 2 (Medium)'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['SCRUB A DUB', 'Risk']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 8\n",
    "<span  style=\"color:green; font-size:16px\">Select every 3,000th restaurant from **`THRESHOLD SCHOOL`** to **`SCRUB A DUB`** and the columns from **`Inspection Type`** on to the end of the DataFrame.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Inspection Type</th>\n",
       "      <th>Results</th>\n",
       "      <th>Violations</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DBA Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>THRESHOLD SCHOOL</th>\n",
       "      <td>Canvass</td>\n",
       "      <td>Pass</td>\n",
       "      <td>38. VENTILATION: ROOMS AND EQUIPMENT VENTED AS...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SAN JOSE FAST FOOD</th>\n",
       "      <td>Canvass</td>\n",
       "      <td>Out of Business</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>CHUCHOS ON ADDISON INC</th>\n",
       "      <td>Canvass</td>\n",
       "      <td>Pass w/ Conditions</td>\n",
       "      <td>33. FOOD AND NON-FOOD CONTACT EQUIPMENT UTENSI...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PIZZERIA AROMA</th>\n",
       "      <td>Canvass Re-Inspection</td>\n",
       "      <td>Pass</td>\n",
       "      <td>2. FACILITIES TO MAINTAIN PROPER TEMPERATURE -...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>JEWEL FOOD STORE #3210</th>\n",
       "      <td>Canvass</td>\n",
       "      <td>No Entry</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>EGANS TAVERN</th>\n",
       "      <td>Canvass</td>\n",
       "      <td>Out of Business</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Los Amigos Grill</th>\n",
       "      <td>Canvass</td>\n",
       "      <td>Out of Business</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>JOHNNY VAN'S SMOKEHOUSE</th>\n",
       "      <td>License</td>\n",
       "      <td>Pass</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WEN   CAFE INC</th>\n",
       "      <td>Out of Business</td>\n",
       "      <td>Fail</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                               Inspection Type             Results  \\\n",
       "DBA Name                                                             \n",
       "THRESHOLD SCHOOL                       Canvass                Pass   \n",
       "SAN JOSE FAST FOOD                     Canvass     Out of Business   \n",
       "CHUCHOS ON ADDISON INC                 Canvass  Pass w/ Conditions   \n",
       "PIZZERIA AROMA           Canvass Re-Inspection                Pass   \n",
       "JEWEL FOOD STORE #3210                 Canvass            No Entry   \n",
       "EGANS TAVERN                           Canvass     Out of Business   \n",
       "Los Amigos Grill                       Canvass     Out of Business   \n",
       "JOHNNY VAN'S SMOKEHOUSE                License                Pass   \n",
       "WEN   CAFE INC                 Out of Business                Fail   \n",
       "\n",
       "                                                                Violations  \n",
       "DBA Name                                                                    \n",
       "THRESHOLD SCHOOL         38. VENTILATION: ROOMS AND EQUIPMENT VENTED AS...  \n",
       "SAN JOSE FAST FOOD                                                     NaN  \n",
       "CHUCHOS ON ADDISON INC   33. FOOD AND NON-FOOD CONTACT EQUIPMENT UTENSI...  \n",
       "PIZZERIA AROMA           2. FACILITIES TO MAINTAIN PROPER TEMPERATURE -...  \n",
       "JEWEL FOOD STORE #3210                                                 NaN  \n",
       "EGANS TAVERN                                                           NaN  \n",
       "Los Amigos Grill                                                       NaN  \n",
       "JOHNNY VAN'S SMOKEHOUSE                                                NaN  \n",
       "WEN   CAFE INC                                                         NaN  "
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['THRESHOLD SCHOOL':'SCRUB A DUB':3000, 'Inspection Type':]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 9\n",
    "<span  style=\"color:green; font-size:16px\">Select all columns from the 500th restaurant to the 510th</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Facility Type</th>\n",
       "      <th>Risk</th>\n",
       "      <th>Address</th>\n",
       "      <th>Zip</th>\n",
       "      <th>Inspection Date</th>\n",
       "      <th>Inspection Type</th>\n",
       "      <th>Results</th>\n",
       "      <th>Violations</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DBA Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>THE MECCA RESTAURANT</th>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>6666 N NORTHWEST HWY</td>\n",
       "      <td>60631.0</td>\n",
       "      <td>03/14/2017</td>\n",
       "      <td>Canvass</td>\n",
       "      <td>Pass w/ Conditions</td>\n",
       "      <td>8. SANITIZING RINSE FOR EQUIPMENT AND UTENSILS...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>L &amp; T CHINA FAST WOK INC.</th>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>2020 N CALIFORNIA AVE</td>\n",
       "      <td>60647.0</td>\n",
       "      <td>03/14/2017</td>\n",
       "      <td>Canvass</td>\n",
       "      <td>Pass</td>\n",
       "      <td>33. FOOD AND NON-FOOD CONTACT EQUIPMENT UTENSI...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>SCHNEIDER  SENIOR  APARTMENT</th>\n",
       "      <td>Golden Diner</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>1750 W PETERSON AVE</td>\n",
       "      <td>60660.0</td>\n",
       "      <td>03/14/2017</td>\n",
       "      <td>Canvass Re-Inspection</td>\n",
       "      <td>Pass</td>\n",
       "      <td>35. WALLS, CEILINGS, ATTACHED EQUIPMENT CONSTR...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ECKHARDT CAFE</th>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>5640 S ELLIS AVE</td>\n",
       "      <td>60637.0</td>\n",
       "      <td>03/14/2017</td>\n",
       "      <td>Canvass</td>\n",
       "      <td>Pass</td>\n",
       "      <td>33. FOOD AND NON-FOOD CONTACT EQUIPMENT UTENSI...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>WING ZONE</th>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>1757 W 87TH ST</td>\n",
       "      <td>60620.0</td>\n",
       "      <td>03/14/2017</td>\n",
       "      <td>Canvass</td>\n",
       "      <td>Out of Business</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>ARBYS</th>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>500 W MADISON ST</td>\n",
       "      <td>60661.0</td>\n",
       "      <td>03/14/2017</td>\n",
       "      <td>Canvass</td>\n",
       "      <td>Pass</td>\n",
       "      <td>34. FLOORS: CONSTRUCTED PER CODE, CLEANED, GOO...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LAS ISLAS MARIAS</th>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>8205-8209 S PULASKI RD</td>\n",
       "      <td>60652.0</td>\n",
       "      <td>03/14/2017</td>\n",
       "      <td>Canvass</td>\n",
       "      <td>Pass</td>\n",
       "      <td>30. FOOD IN ORIGINAL CONTAINER, PROPERLY LABEL...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>MARGARET'S</th>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "      <td>5134 W IRVING PARK RD</td>\n",
       "      <td>60641.0</td>\n",
       "      <td>03/14/2017</td>\n",
       "      <td>Canvass</td>\n",
       "      <td>Pass</td>\n",
       "      <td>33. FOOD AND NON-FOOD CONTACT EQUIPMENT UTENSI...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>POPEYES FAMOUS FRIED CHICKEN</th>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 2 (Medium)</td>\n",
       "      <td>9516 S VINCENNES AVE</td>\n",
       "      <td>60643.0</td>\n",
       "      <td>03/14/2017</td>\n",
       "      <td>Complaint</td>\n",
       "      <td>Pass w/ Conditions</td>\n",
       "      <td>3. POTENTIALLY HAZARDOUS FOOD MEETS TEMPERATUR...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PJ PIZZA COMPANY 1 DBA PAPA JOHNS</th>\n",
       "      <td>Restaurant</td>\n",
       "      <td>Risk 2 (Medium)</td>\n",
       "      <td>1755 W 87TH ST</td>\n",
       "      <td>60620.0</td>\n",
       "      <td>03/14/2017</td>\n",
       "      <td>Canvass</td>\n",
       "      <td>Out of Business</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                  Facility Type             Risk  \\\n",
       "DBA Name                                                           \n",
       "THE MECCA RESTAURANT                 Restaurant    Risk 1 (High)   \n",
       "L & T CHINA FAST WOK INC.            Restaurant    Risk 1 (High)   \n",
       "SCHNEIDER  SENIOR  APARTMENT       Golden Diner    Risk 1 (High)   \n",
       "ECKHARDT CAFE                        Restaurant    Risk 1 (High)   \n",
       "WING ZONE                            Restaurant    Risk 1 (High)   \n",
       "ARBYS                                Restaurant    Risk 1 (High)   \n",
       "LAS ISLAS MARIAS                     Restaurant    Risk 1 (High)   \n",
       "MARGARET'S                           Restaurant    Risk 1 (High)   \n",
       "POPEYES FAMOUS FRIED CHICKEN         Restaurant  Risk 2 (Medium)   \n",
       "PJ PIZZA COMPANY 1 DBA PAPA JOHNS    Restaurant  Risk 2 (Medium)   \n",
       "\n",
       "                                                   Address      Zip  \\\n",
       "DBA Name                                                              \n",
       "THE MECCA RESTAURANT                 6666 N NORTHWEST HWY   60631.0   \n",
       "L & T CHINA FAST WOK INC.           2020 N CALIFORNIA AVE   60647.0   \n",
       "SCHNEIDER  SENIOR  APARTMENT          1750 W PETERSON AVE   60660.0   \n",
       "ECKHARDT CAFE                            5640 S ELLIS AVE   60637.0   \n",
       "WING ZONE                                  1757 W 87TH ST   60620.0   \n",
       "ARBYS                                    500 W MADISON ST   60661.0   \n",
       "LAS ISLAS MARIAS                   8205-8209 S PULASKI RD   60652.0   \n",
       "MARGARET'S                          5134 W IRVING PARK RD   60641.0   \n",
       "POPEYES FAMOUS FRIED CHICKEN         9516 S VINCENNES AVE   60643.0   \n",
       "PJ PIZZA COMPANY 1 DBA PAPA JOHNS          1755 W 87TH ST   60620.0   \n",
       "\n",
       "                                  Inspection Date        Inspection Type  \\\n",
       "DBA Name                                                                   \n",
       "THE MECCA RESTAURANT                   03/14/2017                Canvass   \n",
       "L & T CHINA FAST WOK INC.              03/14/2017                Canvass   \n",
       "SCHNEIDER  SENIOR  APARTMENT           03/14/2017  Canvass Re-Inspection   \n",
       "ECKHARDT CAFE                          03/14/2017                Canvass   \n",
       "WING ZONE                              03/14/2017                Canvass   \n",
       "ARBYS                                  03/14/2017                Canvass   \n",
       "LAS ISLAS MARIAS                       03/14/2017                Canvass   \n",
       "MARGARET'S                             03/14/2017                Canvass   \n",
       "POPEYES FAMOUS FRIED CHICKEN           03/14/2017              Complaint   \n",
       "PJ PIZZA COMPANY 1 DBA PAPA JOHNS      03/14/2017                Canvass   \n",
       "\n",
       "                                              Results  \\\n",
       "DBA Name                                                \n",
       "THE MECCA RESTAURANT               Pass w/ Conditions   \n",
       "L & T CHINA FAST WOK INC.                        Pass   \n",
       "SCHNEIDER  SENIOR  APARTMENT                     Pass   \n",
       "ECKHARDT CAFE                                    Pass   \n",
       "WING ZONE                             Out of Business   \n",
       "ARBYS                                            Pass   \n",
       "LAS ISLAS MARIAS                                 Pass   \n",
       "MARGARET'S                                       Pass   \n",
       "POPEYES FAMOUS FRIED CHICKEN       Pass w/ Conditions   \n",
       "PJ PIZZA COMPANY 1 DBA PAPA JOHNS     Out of Business   \n",
       "\n",
       "                                                                          Violations  \n",
       "DBA Name                                                                              \n",
       "THE MECCA RESTAURANT               8. SANITIZING RINSE FOR EQUIPMENT AND UTENSILS...  \n",
       "L & T CHINA FAST WOK INC.          33. FOOD AND NON-FOOD CONTACT EQUIPMENT UTENSI...  \n",
       "SCHNEIDER  SENIOR  APARTMENT       35. WALLS, CEILINGS, ATTACHED EQUIPMENT CONSTR...  \n",
       "ECKHARDT CAFE                      33. FOOD AND NON-FOOD CONTACT EQUIPMENT UTENSI...  \n",
       "WING ZONE                                                                        NaN  \n",
       "ARBYS                              34. FLOORS: CONSTRUCTED PER CODE, CLEANED, GOO...  \n",
       "LAS ISLAS MARIAS                   30. FOOD IN ORIGINAL CONTAINER, PROPERLY LABEL...  \n",
       "MARGARET'S                         33. FOOD AND NON-FOOD CONTACT EQUIPMENT UTENSI...  \n",
       "POPEYES FAMOUS FRIED CHICKEN       3. POTENTIALLY HAZARDOUS FOOD MEETS TEMPERATUR...  \n",
       "PJ PIZZA COMPANY 1 DBA PAPA JOHNS                                                NaN  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[500:510]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 10\n",
    "<span  style=\"color:green; font-size:16px\">Select restaurants 100, 1,000 and 10,000 along with columns 5, 3, and 1</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Inspection Type</th>\n",
       "      <th>Zip</th>\n",
       "      <th>Risk</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>DBA Name</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>TAQUERIA LA CANTERA</th>\n",
       "      <td>License</td>\n",
       "      <td>60608.0</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>PARK TAVERN CHICAGO</th>\n",
       "      <td>Complaint</td>\n",
       "      <td>60612.0</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>LITTLE VILLAGE HIGH SCHOOL</th>\n",
       "      <td>Canvass</td>\n",
       "      <td>60623.0</td>\n",
       "      <td>Risk 1 (High)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                           Inspection Type      Zip           Risk\n",
       "DBA Name                                                          \n",
       "TAQUERIA LA CANTERA                License  60608.0  Risk 1 (High)\n",
       "PARK TAVERN CHICAGO              Complaint  60612.0  Risk 1 (High)\n",
       "LITTLE VILLAGE HIGH SCHOOL         Canvass  60623.0  Risk 1 (High)"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[[100, 1000, 10000], [5, 3, 1]]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 11\n",
    "<span  style=\"color:green; font-size:16px\">Select the **`Risk`** column and save it to a Series</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DBA Name\n",
       "DANY'S TACOS                 Risk 1 (High)\n",
       "BILLY FOOD MARKET INC         Risk 3 (Low)\n",
       "TAQUERIA HACIENDA TAPATIA    Risk 1 (High)\n",
       "WILD GOOSE BAR & GRILL       Risk 1 (High)\n",
       "PUBLICAN TAVERN K1           Risk 1 (High)\n",
       "Name: Risk, dtype: object"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "risk = df['Risk']\n",
    "risk.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 12\n",
    "<span  style=\"color:green; font-size:16px\">Using the risk Series, select **`ARBYS`** and **`POPEYES FAMOUS FRIED CHICKEN`**</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "DBA Name\n",
       "ARBYS                             Risk 1 (High)\n",
       "POPEYES FAMOUS FRIED CHICKEN    Risk 2 (Medium)\n",
       "Name: Risk, dtype: object"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "risk.loc[['ARBYS', 'POPEYES FAMOUS FRIED CHICKEN']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# Part 2: Boolean Indexing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>creationdate</th>\n",
       "      <th>score</th>\n",
       "      <th>viewcount</th>\n",
       "      <th>title</th>\n",
       "      <th>answercount</th>\n",
       "      <th>commentcount</th>\n",
       "      <th>favoritecount</th>\n",
       "      <th>quest_name</th>\n",
       "      <th>quest_rep</th>\n",
       "      <th>ans_name</th>\n",
       "      <th>ans_rep</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>5486226</td>\n",
       "      <td>2011-03-30 12:26:50</td>\n",
       "      <td>4</td>\n",
       "      <td>2113</td>\n",
       "      <td>Rolling median in python</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>1.0</td>\n",
       "      <td>yueerhu</td>\n",
       "      <td>125.0</td>\n",
       "      <td>Mike Pennington</td>\n",
       "      <td>26995.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>5515021</td>\n",
       "      <td>2011-04-01 14:50:44</td>\n",
       "      <td>8</td>\n",
       "      <td>7015</td>\n",
       "      <td>Compute a compounded return series in Python</td>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "      <td>7.0</td>\n",
       "      <td>Jason Strimpel</td>\n",
       "      <td>3301.0</td>\n",
       "      <td>Mike Pennington</td>\n",
       "      <td>26995.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>5558607</td>\n",
       "      <td>2011-04-05 21:13:50</td>\n",
       "      <td>2</td>\n",
       "      <td>7392</td>\n",
       "      <td>Sort a pandas DataMatrix in ascending order</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>Jason Strimpel</td>\n",
       "      <td>3301.0</td>\n",
       "      <td>Wes McKinney</td>\n",
       "      <td>43310.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>6467832</td>\n",
       "      <td>2011-06-24 12:31:45</td>\n",
       "      <td>9</td>\n",
       "      <td>13056</td>\n",
       "      <td>How to get the correlation between two timeser...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>7.0</td>\n",
       "      <td>user814005</td>\n",
       "      <td>117.0</td>\n",
       "      <td>Wes McKinney</td>\n",
       "      <td>43310.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>7577546</td>\n",
       "      <td>2011-09-28 01:58:38</td>\n",
       "      <td>9</td>\n",
       "      <td>2488</td>\n",
       "      <td>Using pandas, how do I subsample a large DataF...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Uri Laserson</td>\n",
       "      <td>958.0</td>\n",
       "      <td>HYRY</td>\n",
       "      <td>54137.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "        id         creationdate  score  viewcount  \\\n",
       "0  5486226  2011-03-30 12:26:50      4       2113   \n",
       "1  5515021  2011-04-01 14:50:44      8       7015   \n",
       "2  5558607  2011-04-05 21:13:50      2       7392   \n",
       "3  6467832  2011-06-24 12:31:45      9      13056   \n",
       "4  7577546  2011-09-28 01:58:38      9       2488   \n",
       "\n",
       "                                               title  answercount  \\\n",
       "0                           Rolling median in python            3   \n",
       "1       Compute a compounded return series in Python            3   \n",
       "2        Sort a pandas DataMatrix in ascending order            2   \n",
       "3  How to get the correlation between two timeser...            1   \n",
       "4  Using pandas, how do I subsample a large DataF...            1   \n",
       "\n",
       "   commentcount  favoritecount      quest_name  quest_rep         ans_name  \\\n",
       "0             4            1.0         yueerhu      125.0  Mike Pennington   \n",
       "1             6            7.0  Jason Strimpel     3301.0  Mike Pennington   \n",
       "2             0            1.0  Jason Strimpel     3301.0     Wes McKinney   \n",
       "3             0            7.0      user814005      117.0     Wes McKinney   \n",
       "4             0            5.0    Uri Laserson      958.0             HYRY   \n",
       "\n",
       "   ans_rep  \n",
       "0  26995.0  \n",
       "1  26995.0  \n",
       "2  43310.0  \n",
       "3  43310.0  \n",
       "4  54137.0  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "so = pd.read_csv('../../data/stackoverflow_qa.csv')\n",
    "so.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 1\n",
    "<span  style=\"color:green; font-size:16px\">Find all the questions that have exactly 5 answers.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>creationdate</th>\n",
       "      <th>score</th>\n",
       "      <th>viewcount</th>\n",
       "      <th>title</th>\n",
       "      <th>answercount</th>\n",
       "      <th>commentcount</th>\n",
       "      <th>favoritecount</th>\n",
       "      <th>quest_name</th>\n",
       "      <th>quest_rep</th>\n",
       "      <th>ans_name</th>\n",
       "      <th>ans_rep</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>75</th>\n",
       "      <td>10373660</td>\n",
       "      <td>2012-04-29 16:10:35</td>\n",
       "      <td>199</td>\n",
       "      <td>207980</td>\n",
       "      <td>Converting a Pandas GroupBy object to DataFrame</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>90.0</td>\n",
       "      <td>saveenr</td>\n",
       "      <td>2421.0</td>\n",
       "      <td>Wes McKinney</td>\n",
       "      <td>43310.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>115</th>\n",
       "      <td>10791661</td>\n",
       "      <td>2012-05-29 00:06:52</td>\n",
       "      <td>7</td>\n",
       "      <td>12210</td>\n",
       "      <td>How do I discretize values in a pandas DataFra...</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>Uri Laserson</td>\n",
       "      <td>958.0</td>\n",
       "      <td>lbolla</td>\n",
       "      <td>4552.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>130</th>\n",
       "      <td>10972410</td>\n",
       "      <td>2012-06-10 21:12:43</td>\n",
       "      <td>19</td>\n",
       "      <td>46428</td>\n",
       "      <td>pandas: combine two columns in a DataFrame</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>BFTM</td>\n",
       "      <td>895.0</td>\n",
       "      <td>BrenBarn</td>\n",
       "      <td>136870.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>189</th>\n",
       "      <td>11391969</td>\n",
       "      <td>2012-07-09 09:04:33</td>\n",
       "      <td>44</td>\n",
       "      <td>27467</td>\n",
       "      <td>How to group pandas DataFrame entries by date ...</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "      <td>15.0</td>\n",
       "      <td>Boris Gorelik</td>\n",
       "      <td>9605.0</td>\n",
       "      <td>Wes McKinney</td>\n",
       "      <td>43310.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>246</th>\n",
       "      <td>11811392</td>\n",
       "      <td>2012-08-04 19:25:34</td>\n",
       "      <td>17</td>\n",
       "      <td>20051</td>\n",
       "      <td>How to generate a list from a pandas DataFrame...</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>6.0</td>\n",
       "      <td>turtle</td>\n",
       "      <td>1260.0</td>\n",
       "      <td>BrenBarn</td>\n",
       "      <td>136870.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           id         creationdate  score  viewcount  \\\n",
       "75   10373660  2012-04-29 16:10:35    199     207980   \n",
       "115  10791661  2012-05-29 00:06:52      7      12210   \n",
       "130  10972410  2012-06-10 21:12:43     19      46428   \n",
       "189  11391969  2012-07-09 09:04:33     44      27467   \n",
       "246  11811392  2012-08-04 19:25:34     17      20051   \n",
       "\n",
       "                                                 title  answercount  \\\n",
       "75     Converting a Pandas GroupBy object to DataFrame            5   \n",
       "115  How do I discretize values in a pandas DataFra...            5   \n",
       "130         pandas: combine two columns in a DataFrame            5   \n",
       "189  How to group pandas DataFrame entries by date ...            5   \n",
       "246  How to generate a list from a pandas DataFrame...            5   \n",
       "\n",
       "     commentcount  favoritecount     quest_name  quest_rep      ans_name  \\\n",
       "75              0           90.0        saveenr     2421.0  Wes McKinney   \n",
       "115             0            3.0   Uri Laserson      958.0        lbolla   \n",
       "130             0            5.0           BFTM      895.0      BrenBarn   \n",
       "189             1           15.0  Boris Gorelik     9605.0  Wes McKinney   \n",
       "246             0            6.0         turtle     1260.0      BrenBarn   \n",
       "\n",
       "      ans_rep  \n",
       "75    43310.0  \n",
       "115    4552.0  \n",
       "130  136870.0  \n",
       "189   43310.0  \n",
       "246  136870.0  "
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "so[so['answercount'] == 5].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 2\n",
    "<span  style=\"color:green; font-size:16px\">Find all the questions that have less than 10 views</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>creationdate</th>\n",
       "      <th>score</th>\n",
       "      <th>viewcount</th>\n",
       "      <th>title</th>\n",
       "      <th>answercount</th>\n",
       "      <th>commentcount</th>\n",
       "      <th>favoritecount</th>\n",
       "      <th>quest_name</th>\n",
       "      <th>quest_rep</th>\n",
       "      <th>ans_name</th>\n",
       "      <th>ans_rep</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>7787</th>\n",
       "      <td>26493306</td>\n",
       "      <td>2014-10-21 18:06:10</td>\n",
       "      <td>1</td>\n",
       "      <td>6</td>\n",
       "      <td>How to convert hierarchical DataFrame back fro...</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1.0</td>\n",
       "      <td>exp1orer</td>\n",
       "      <td>3551.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17653</th>\n",
       "      <td>33641540</td>\n",
       "      <td>2015-11-10 23:19:36</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>Joining Dataframes in Pandas deletes an existi...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Rahul Biswas</td>\n",
       "      <td>88.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29414</th>\n",
       "      <td>40062672</td>\n",
       "      <td>2016-10-15 18:24:21</td>\n",
       "      <td>-1</td>\n",
       "      <td>9</td>\n",
       "      <td>Replace one or more sub-strings from multiple ...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Andreuccio</td>\n",
       "      <td>186.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36086</th>\n",
       "      <td>42538091</td>\n",
       "      <td>2017-03-01 17:20:37</td>\n",
       "      <td>0</td>\n",
       "      <td>9</td>\n",
       "      <td>Saving box plot pandas python</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>user2906657</td>\n",
       "      <td>119.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>36340</th>\n",
       "      <td>42080039</td>\n",
       "      <td>2017-02-07 01:13:30</td>\n",
       "      <td>0</td>\n",
       "      <td>8</td>\n",
       "      <td>pandas: count the non-duplicated elements when...</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Edamame</td>\n",
       "      <td>2281.0</td>\n",
       "      <td>root</td>\n",
       "      <td>12202.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             id         creationdate  score  viewcount  \\\n",
       "7787   26493306  2014-10-21 18:06:10      1          6   \n",
       "17653  33641540  2015-11-10 23:19:36      0          9   \n",
       "29414  40062672  2016-10-15 18:24:21     -1          9   \n",
       "36086  42538091  2017-03-01 17:20:37      0          9   \n",
       "36340  42080039  2017-02-07 01:13:30      0          8   \n",
       "\n",
       "                                                   title  answercount  \\\n",
       "7787   How to convert hierarchical DataFrame back fro...            0   \n",
       "17653  Joining Dataframes in Pandas deletes an existi...            1   \n",
       "29414  Replace one or more sub-strings from multiple ...            1   \n",
       "36086                      Saving box plot pandas python            0   \n",
       "36340  pandas: count the non-duplicated elements when...            1   \n",
       "\n",
       "       commentcount  favoritecount    quest_name  quest_rep ans_name  ans_rep  \n",
       "7787              2            1.0      exp1orer     3551.0      NaN      NaN  \n",
       "17653             0            NaN  Rahul Biswas       88.0      NaN      NaN  \n",
       "29414             0            NaN    Andreuccio      186.0      NaN      NaN  \n",
       "36086             0            NaN   user2906657      119.0      NaN      NaN  \n",
       "36340             0            NaN       Edamame     2281.0     root  12202.0  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "so[so['viewcount'] < 10].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 3\n",
    "<span  style=\"color:green; font-size:16px\">Find all the questions where the person asking it is the same as the person answering it</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>creationdate</th>\n",
       "      <th>score</th>\n",
       "      <th>viewcount</th>\n",
       "      <th>title</th>\n",
       "      <th>answercount</th>\n",
       "      <th>commentcount</th>\n",
       "      <th>favoritecount</th>\n",
       "      <th>quest_name</th>\n",
       "      <th>quest_rep</th>\n",
       "      <th>ans_name</th>\n",
       "      <th>ans_rep</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>8273092</td>\n",
       "      <td>2011-11-25 18:39:02</td>\n",
       "      <td>1</td>\n",
       "      <td>2333</td>\n",
       "      <td>python: pandas install errors</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>codingknob</td>\n",
       "      <td>2279.0</td>\n",
       "      <td>codingknob</td>\n",
       "      <td>2279.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>33</th>\n",
       "      <td>9721429</td>\n",
       "      <td>2012-03-15 14:08:31</td>\n",
       "      <td>9</td>\n",
       "      <td>5732</td>\n",
       "      <td>How do I read a fix width format text file in ...</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>user1234440</td>\n",
       "      <td>3369.0</td>\n",
       "      <td>user1234440</td>\n",
       "      <td>3369.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>58</th>\n",
       "      <td>10020591</td>\n",
       "      <td>2012-04-04 23:17:23</td>\n",
       "      <td>21</td>\n",
       "      <td>20171</td>\n",
       "      <td>How to resample a dataframe with different fun...</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>15.0</td>\n",
       "      <td>bmu</td>\n",
       "      <td>17129.0</td>\n",
       "      <td>bmu</td>\n",
       "      <td>17129.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>68</th>\n",
       "      <td>10175068</td>\n",
       "      <td>2012-04-16 13:27:44</td>\n",
       "      <td>15</td>\n",
       "      <td>7501</td>\n",
       "      <td>Select data at a particular level from a Multi...</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>5.0</td>\n",
       "      <td>elyase</td>\n",
       "      <td>19551.0</td>\n",
       "      <td>elyase</td>\n",
       "      <td>19551.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>74</th>\n",
       "      <td>10264739</td>\n",
       "      <td>2012-04-22 02:35:06</td>\n",
       "      <td>9</td>\n",
       "      <td>2362</td>\n",
       "      <td>major memory problems reading in a csv file us...</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>7.0</td>\n",
       "      <td>vgoklani</td>\n",
       "      <td>1752.0</td>\n",
       "      <td>vgoklani</td>\n",
       "      <td>1752.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          id         creationdate  score  viewcount  \\\n",
       "10   8273092  2011-11-25 18:39:02      1       2333   \n",
       "33   9721429  2012-03-15 14:08:31      9       5732   \n",
       "58  10020591  2012-04-04 23:17:23     21      20171   \n",
       "68  10175068  2012-04-16 13:27:44     15       7501   \n",
       "74  10264739  2012-04-22 02:35:06      9       2362   \n",
       "\n",
       "                                                title  answercount  \\\n",
       "10                      python: pandas install errors            2   \n",
       "33  How do I read a fix width format text file in ...            4   \n",
       "58  How to resample a dataframe with different fun...            4   \n",
       "68  Select data at a particular level from a Multi...            2   \n",
       "74  major memory problems reading in a csv file us...            3   \n",
       "\n",
       "    commentcount  favoritecount   quest_name  quest_rep     ans_name  ans_rep  \n",
       "10             0            NaN   codingknob     2279.0   codingknob   2279.0  \n",
       "33             2            NaN  user1234440     3369.0  user1234440   3369.0  \n",
       "58             0           15.0          bmu    17129.0          bmu  17129.0  \n",
       "68             3            5.0       elyase    19551.0       elyase  19551.0  \n",
       "74             2            7.0     vgoklani     1752.0     vgoklani   1752.0  "
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "so[so['quest_name'] == so['ans_name']].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 4\n",
    "<span  style=\"color:green; font-size:16px\">Find all the questions that don't have an accepted answer, but have a score of more than 100</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>creationdate</th>\n",
       "      <th>score</th>\n",
       "      <th>viewcount</th>\n",
       "      <th>title</th>\n",
       "      <th>answercount</th>\n",
       "      <th>commentcount</th>\n",
       "      <th>favoritecount</th>\n",
       "      <th>quest_name</th>\n",
       "      <th>quest_rep</th>\n",
       "      <th>ans_name</th>\n",
       "      <th>ans_rep</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>184</th>\n",
       "      <td>11350770</td>\n",
       "      <td>2012-07-05 18:57:34</td>\n",
       "      <td>149</td>\n",
       "      <td>155776</td>\n",
       "      <td>pandas + dataframe - select by partial string</td>\n",
       "      <td>7</td>\n",
       "      <td>0</td>\n",
       "      <td>52.0</td>\n",
       "      <td>euforia</td>\n",
       "      <td>816.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>514</th>\n",
       "      <td>13148429</td>\n",
       "      <td>2012-10-30 22:22:59</td>\n",
       "      <td>312</td>\n",
       "      <td>228357</td>\n",
       "      <td>How to change the order of DataFrame columns?</td>\n",
       "      <td>19</td>\n",
       "      <td>1</td>\n",
       "      <td>90.0</td>\n",
       "      <td>Timmie</td>\n",
       "      <td>1689.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>527</th>\n",
       "      <td>13187778</td>\n",
       "      <td>2012-11-02 00:57:33</td>\n",
       "      <td>102</td>\n",
       "      <td>202329</td>\n",
       "      <td>Convert pandas dataframe to numpy array, prese...</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>45.0</td>\n",
       "      <td>mister.nobody.nz</td>\n",
       "      <td>511.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>560</th>\n",
       "      <td>13331698</td>\n",
       "      <td>2012-11-11 13:48:53</td>\n",
       "      <td>154</td>\n",
       "      <td>174964</td>\n",
       "      <td>How to apply a function to two columns of Pand...</td>\n",
       "      <td>9</td>\n",
       "      <td>4</td>\n",
       "      <td>66.0</td>\n",
       "      <td>bigbug</td>\n",
       "      <td>7865.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5013</th>\n",
       "      <td>19377969</td>\n",
       "      <td>2013-10-15 09:42:52</td>\n",
       "      <td>128</td>\n",
       "      <td>144045</td>\n",
       "      <td>Combine two columns of text in dataframe in pa...</td>\n",
       "      <td>10</td>\n",
       "      <td>1</td>\n",
       "      <td>49.0</td>\n",
       "      <td>user2866103</td>\n",
       "      <td>831.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5370</th>\n",
       "      <td>20845213</td>\n",
       "      <td>2013-12-30 18:24:25</td>\n",
       "      <td>130</td>\n",
       "      <td>61332</td>\n",
       "      <td>How to avoid Python/Pandas creating an index i...</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>14.0</td>\n",
       "      <td>Alexis</td>\n",
       "      <td>835.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8289</th>\n",
       "      <td>26266362</td>\n",
       "      <td>2014-10-08 21:00:19</td>\n",
       "      <td>132</td>\n",
       "      <td>108655</td>\n",
       "      <td>How to count the Nan values in the column in P...</td>\n",
       "      <td>9</td>\n",
       "      <td>0</td>\n",
       "      <td>39.0</td>\n",
       "      <td>user3799307</td>\n",
       "      <td>661.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            id         creationdate  score  viewcount  \\\n",
       "184   11350770  2012-07-05 18:57:34    149     155776   \n",
       "514   13148429  2012-10-30 22:22:59    312     228357   \n",
       "527   13187778  2012-11-02 00:57:33    102     202329   \n",
       "560   13331698  2012-11-11 13:48:53    154     174964   \n",
       "5013  19377969  2013-10-15 09:42:52    128     144045   \n",
       "5370  20845213  2013-12-30 18:24:25    130      61332   \n",
       "8289  26266362  2014-10-08 21:00:19    132     108655   \n",
       "\n",
       "                                                  title  answercount  \\\n",
       "184       pandas + dataframe - select by partial string            7   \n",
       "514       How to change the order of DataFrame columns?           19   \n",
       "527   Convert pandas dataframe to numpy array, prese...            8   \n",
       "560   How to apply a function to two columns of Pand...            9   \n",
       "5013  Combine two columns of text in dataframe in pa...           10   \n",
       "5370  How to avoid Python/Pandas creating an index i...            3   \n",
       "8289  How to count the Nan values in the column in P...            9   \n",
       "\n",
       "      commentcount  favoritecount        quest_name  quest_rep ans_name  \\\n",
       "184              0           52.0           euforia      816.0      NaN   \n",
       "514              1           90.0            Timmie     1689.0      NaN   \n",
       "527              0           45.0  mister.nobody.nz      511.0      NaN   \n",
       "560              4           66.0            bigbug     7865.0      NaN   \n",
       "5013             1           49.0       user2866103      831.0      NaN   \n",
       "5370             3           14.0            Alexis      835.0      NaN   \n",
       "8289             0           39.0       user3799307      661.0      NaN   \n",
       "\n",
       "      ans_rep  \n",
       "184       NaN  \n",
       "514       NaN  \n",
       "527       NaN  \n",
       "560       NaN  \n",
       "5013      NaN  \n",
       "5370      NaN  \n",
       "8289      NaN  "
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "so[so['ans_name'].isnull() & (so['score'] > 100)]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 5\n",
    "<span  style=\"color:green; font-size:16px\">Find all the questions where the reputation of the person asking the question is higher than the person answering it. Then find the percentage of times this happens</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>creationdate</th>\n",
       "      <th>score</th>\n",
       "      <th>viewcount</th>\n",
       "      <th>title</th>\n",
       "      <th>answercount</th>\n",
       "      <th>commentcount</th>\n",
       "      <th>favoritecount</th>\n",
       "      <th>quest_name</th>\n",
       "      <th>quest_rep</th>\n",
       "      <th>ans_name</th>\n",
       "      <th>ans_rep</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>9588331</td>\n",
       "      <td>2012-03-06 17:01:47</td>\n",
       "      <td>22</td>\n",
       "      <td>10038</td>\n",
       "      <td>Simple cross-tabulation in pandas</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>5.0</td>\n",
       "      <td>Jon Clements</td>\n",
       "      <td>85944.0</td>\n",
       "      <td>Jeff Hammerbacher</td>\n",
       "      <td>3172.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>51</th>\n",
       "      <td>9962114</td>\n",
       "      <td>2012-04-01 05:25:20</td>\n",
       "      <td>9</td>\n",
       "      <td>8079</td>\n",
       "      <td>Control Charts in Python</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>John</td>\n",
       "      <td>8807.0</td>\n",
       "      <td>Josh Hemann</td>\n",
       "      <td>590.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99</th>\n",
       "      <td>10636024</td>\n",
       "      <td>2012-05-17 12:48:00</td>\n",
       "      <td>36</td>\n",
       "      <td>30386</td>\n",
       "      <td>Python / Pandas - GUI for viewing a DataFrame ...</td>\n",
       "      <td>15</td>\n",
       "      <td>6</td>\n",
       "      <td>27.0</td>\n",
       "      <td>Ross R</td>\n",
       "      <td>1562.0</td>\n",
       "      <td>user1319128</td>\n",
       "      <td>555.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>101</th>\n",
       "      <td>10671227</td>\n",
       "      <td>2012-05-20 06:14:57</td>\n",
       "      <td>0</td>\n",
       "      <td>473</td>\n",
       "      <td>Pandas FloatingPoint Error</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>NaN</td>\n",
       "      <td>tshauck</td>\n",
       "      <td>5957.0</td>\n",
       "      <td>Karmel</td>\n",
       "      <td>2870.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>112</th>\n",
       "      <td>10760364</td>\n",
       "      <td>2012-05-25 19:33:39</td>\n",
       "      <td>8</td>\n",
       "      <td>2977</td>\n",
       "      <td>\"Zebra Tables\" in IPython Notebook?</td>\n",
       "      <td>3</td>\n",
       "      <td>0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>JD Long</td>\n",
       "      <td>33098.0</td>\n",
       "      <td>minrk</td>\n",
       "      <td>22244.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           id         creationdate  score  viewcount  \\\n",
       "26    9588331  2012-03-06 17:01:47     22      10038   \n",
       "51    9962114  2012-04-01 05:25:20      9       8079   \n",
       "99   10636024  2012-05-17 12:48:00     36      30386   \n",
       "101  10671227  2012-05-20 06:14:57      0        473   \n",
       "112  10760364  2012-05-25 19:33:39      8       2977   \n",
       "\n",
       "                                                 title  answercount  \\\n",
       "26                   Simple cross-tabulation in pandas            2   \n",
       "51                            Control Charts in Python            1   \n",
       "99   Python / Pandas - GUI for viewing a DataFrame ...           15   \n",
       "101                         Pandas FloatingPoint Error            1   \n",
       "112                \"Zebra Tables\" in IPython Notebook?            3   \n",
       "\n",
       "     commentcount  favoritecount    quest_name  quest_rep           ans_name  \\\n",
       "26              3            5.0  Jon Clements    85944.0  Jeff Hammerbacher   \n",
       "51              0            3.0          John     8807.0        Josh Hemann   \n",
       "99              6           27.0        Ross R     1562.0        user1319128   \n",
       "101             5            NaN       tshauck     5957.0             Karmel   \n",
       "112             0            4.0       JD Long    33098.0              minrk   \n",
       "\n",
       "     ans_rep  \n",
       "26    3172.0  \n",
       "51     590.0  \n",
       "99     555.0  \n",
       "101   2870.0  \n",
       "112  22244.0  "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "quest_higher_rep = so[so['quest_rep'] > so['ans_rep']]\n",
    "quest_higher_rep.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.039717720486542075"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# about 4% of the time\n",
    "len(quest_higher_rep) / len(so)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.039717720486542075"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# advanced - same solution\n",
    "(so['quest_rep'] > so['ans_rep']).mean()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 6\n",
    "<span  style=\"color:green; font-size:16px\">Find all the questions where the number of answers is between 5 and 10 inclusive and the number of views is less than 1,000.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>id</th>\n",
       "      <th>creationdate</th>\n",
       "      <th>score</th>\n",
       "      <th>viewcount</th>\n",
       "      <th>title</th>\n",
       "      <th>answercount</th>\n",
       "      <th>commentcount</th>\n",
       "      <th>favoritecount</th>\n",
       "      <th>quest_name</th>\n",
       "      <th>quest_rep</th>\n",
       "      <th>ans_name</th>\n",
       "      <th>ans_rep</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>620</th>\n",
       "      <td>13580875</td>\n",
       "      <td>2012-11-27 09:19:07</td>\n",
       "      <td>2</td>\n",
       "      <td>963</td>\n",
       "      <td>Running average / frequency of time series data?</td>\n",
       "      <td>5</td>\n",
       "      <td>9</td>\n",
       "      <td>1.0</td>\n",
       "      <td>Prof. Falken</td>\n",
       "      <td>15061.0</td>\n",
       "      <td>Victor K</td>\n",
       "      <td>332.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1316</th>\n",
       "      <td>14742893</td>\n",
       "      <td>2013-02-07 03:13:31</td>\n",
       "      <td>2</td>\n",
       "      <td>598</td>\n",
       "      <td>Interpolation Function</td>\n",
       "      <td>5</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>eWizardII</td>\n",
       "      <td>886.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4816</th>\n",
       "      <td>21315997</td>\n",
       "      <td>2014-01-23 18:02:57</td>\n",
       "      <td>2</td>\n",
       "      <td>716</td>\n",
       "      <td>Python Pandas vs R. Transformation Code Concis...</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>2.0</td>\n",
       "      <td>user2684301</td>\n",
       "      <td>1465.0</td>\n",
       "      <td>Jeff</td>\n",
       "      <td>62248.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4958</th>\n",
       "      <td>19892107</td>\n",
       "      <td>2013-11-10 16:28:50</td>\n",
       "      <td>5</td>\n",
       "      <td>385</td>\n",
       "      <td>Updating csv with data from a csv with differe...</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>OliverSteph</td>\n",
       "      <td>32.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5339</th>\n",
       "      <td>21040578</td>\n",
       "      <td>2014-01-10 09:33:09</td>\n",
       "      <td>-1</td>\n",
       "      <td>175</td>\n",
       "      <td>combining mutiple csv file</td>\n",
       "      <td>8</td>\n",
       "      <td>2</td>\n",
       "      <td>NaN</td>\n",
       "      <td>user104853</td>\n",
       "      <td>16.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            id         creationdate  score  viewcount  \\\n",
       "620   13580875  2012-11-27 09:19:07      2        963   \n",
       "1316  14742893  2013-02-07 03:13:31      2        598   \n",
       "4816  21315997  2014-01-23 18:02:57      2        716   \n",
       "4958  19892107  2013-11-10 16:28:50      5        385   \n",
       "5339  21040578  2014-01-10 09:33:09     -1        175   \n",
       "\n",
       "                                                  title  answercount  \\\n",
       "620    Running average / frequency of time series data?            5   \n",
       "1316                             Interpolation Function            5   \n",
       "4816  Python Pandas vs R. Transformation Code Concis...            5   \n",
       "4958  Updating csv with data from a csv with differe...            6   \n",
       "5339                         combining mutiple csv file            8   \n",
       "\n",
       "      commentcount  favoritecount    quest_name  quest_rep  ans_name  ans_rep  \n",
       "620              9            1.0  Prof. Falken    15061.0  Victor K    332.0  \n",
       "1316             0            NaN     eWizardII      886.0       NaN      NaN  \n",
       "4816             2            2.0   user2684301     1465.0      Jeff  62248.0  \n",
       "4958             0            1.0   OliverSteph       32.0       NaN      NaN  \n",
       "5339             2            NaN    user104853       16.0       NaN      NaN  "
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "so[so['answercount'].between(5, 10) & (so['viewcount'] < 1000)].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 7\n",
    "<span  style=\"color:green; font-size:16px\">Find the inverse of exercise 6. Verify your results by adding the rows of both returned Series to see if it matches the number of rows of the original</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "ex6 = so[so['answercount'].between(5, 10) & (so['viewcount'] < 1000)]\n",
    "\n",
    "criteria = (so['answercount'].between(5, 10) & (so['viewcount'] < 1000))\n",
    "ex7 = so[~criteria]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "56398"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(ex6) + len(ex7)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "56398"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(so)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Use the employee data for the rest of the exercises"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>POSITION_TITLE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>BASE_SALARY</th>\n",
       "      <th>RACE</th>\n",
       "      <th>EMPLOYMENT_TYPE</th>\n",
       "      <th>GENDER</th>\n",
       "      <th>HIRE_DATE</th>\n",
       "      <th>JOB_DATE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ASSISTANT DIRECTOR (EX LVL)</td>\n",
       "      <td>Municipal Courts Department</td>\n",
       "      <td>121862.0</td>\n",
       "      <td>Hispanic/Latino</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Female</td>\n",
       "      <td>2006-06-12</td>\n",
       "      <td>2012-10-13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>LIBRARY ASSISTANT</td>\n",
       "      <td>Library</td>\n",
       "      <td>26125.0</td>\n",
       "      <td>Hispanic/Latino</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Female</td>\n",
       "      <td>2000-07-19</td>\n",
       "      <td>2010-09-18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>POLICE OFFICER</td>\n",
       "      <td>Houston Police Department-HPD</td>\n",
       "      <td>45279.0</td>\n",
       "      <td>White</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Male</td>\n",
       "      <td>2015-02-03</td>\n",
       "      <td>2015-02-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>ENGINEER/OPERATOR</td>\n",
       "      <td>Houston Fire Department (HFD)</td>\n",
       "      <td>63166.0</td>\n",
       "      <td>White</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Male</td>\n",
       "      <td>1982-02-08</td>\n",
       "      <td>1991-05-25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>ELECTRICIAN</td>\n",
       "      <td>General Services Department</td>\n",
       "      <td>56347.0</td>\n",
       "      <td>White</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Male</td>\n",
       "      <td>1989-06-19</td>\n",
       "      <td>1994-10-22</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                POSITION_TITLE                     DEPARTMENT  BASE_SALARY  \\\n",
       "0  ASSISTANT DIRECTOR (EX LVL)    Municipal Courts Department     121862.0   \n",
       "1            LIBRARY ASSISTANT                        Library      26125.0   \n",
       "2               POLICE OFFICER  Houston Police Department-HPD      45279.0   \n",
       "3            ENGINEER/OPERATOR  Houston Fire Department (HFD)      63166.0   \n",
       "4                  ELECTRICIAN    General Services Department      56347.0   \n",
       "\n",
       "              RACE EMPLOYMENT_TYPE  GENDER   HIRE_DATE    JOB_DATE  \n",
       "0  Hispanic/Latino       Full Time  Female  2006-06-12  2012-10-13  \n",
       "1  Hispanic/Latino       Full Time  Female  2000-07-19  2010-09-18  \n",
       "2            White       Full Time    Male  2015-02-03  2015-02-03  \n",
       "3            White       Full Time    Male  1982-02-08  1991-05-25  \n",
       "4            White       Full Time    Male  1989-06-19  1994-10-22  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "employee = pd.read_csv('../../data/employee.csv')\n",
    "employee.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Black or African American            700\n",
       "White                                665\n",
       "Hispanic/Latino                      480\n",
       "Asian/Pacific Islander               107\n",
       "American Indian or Alaskan Native     11\n",
       "Others                                 2\n",
       "Name: RACE, dtype: int64"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "employee.RACE.value_counts()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 8\n",
    "<span  style=\"color:green; font-size:16px\">Find all the **`Black or African American`** females that work in the **`Houston Police Department-HPD`**</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>POSITION_TITLE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>BASE_SALARY</th>\n",
       "      <th>RACE</th>\n",
       "      <th>EMPLOYMENT_TYPE</th>\n",
       "      <th>GENDER</th>\n",
       "      <th>HIRE_DATE</th>\n",
       "      <th>JOB_DATE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>ADMINISTRATIVE ASSOCIATE</td>\n",
       "      <td>Houston Police Department-HPD</td>\n",
       "      <td>34757.0</td>\n",
       "      <td>Black or African American</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Female</td>\n",
       "      <td>2005-05-11</td>\n",
       "      <td>2008-05-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>113</th>\n",
       "      <td>SENIOR POLICE OFFICER</td>\n",
       "      <td>Houston Police Department-HPD</td>\n",
       "      <td>66614.0</td>\n",
       "      <td>Black or African American</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Female</td>\n",
       "      <td>1994-06-20</td>\n",
       "      <td>2007-02-24</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>137</th>\n",
       "      <td>JAIL ATTENDANT</td>\n",
       "      <td>Houston Police Department-HPD</td>\n",
       "      <td>36317.0</td>\n",
       "      <td>Black or African American</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Female</td>\n",
       "      <td>2008-11-24</td>\n",
       "      <td>2013-07-17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>196</th>\n",
       "      <td>SENIOR POLICE OFFICER</td>\n",
       "      <td>Houston Police Department-HPD</td>\n",
       "      <td>66614.0</td>\n",
       "      <td>Black or African American</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Female</td>\n",
       "      <td>1992-08-31</td>\n",
       "      <td>2008-03-08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>228</th>\n",
       "      <td>FINANCIAL ANALYST III</td>\n",
       "      <td>Houston Police Department-HPD</td>\n",
       "      <td>59182.0</td>\n",
       "      <td>Black or African American</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Female</td>\n",
       "      <td>1985-04-15</td>\n",
       "      <td>2009-07-25</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "               POSITION_TITLE                     DEPARTMENT  BASE_SALARY  \\\n",
       "55   ADMINISTRATIVE ASSOCIATE  Houston Police Department-HPD      34757.0   \n",
       "113     SENIOR POLICE OFFICER  Houston Police Department-HPD      66614.0   \n",
       "137            JAIL ATTENDANT  Houston Police Department-HPD      36317.0   \n",
       "196     SENIOR POLICE OFFICER  Houston Police Department-HPD      66614.0   \n",
       "228     FINANCIAL ANALYST III  Houston Police Department-HPD      59182.0   \n",
       "\n",
       "                          RACE EMPLOYMENT_TYPE  GENDER   HIRE_DATE    JOB_DATE  \n",
       "55   Black or African American       Full Time  Female  2005-05-11  2008-05-17  \n",
       "113  Black or African American       Full Time  Female  1994-06-20  2007-02-24  \n",
       "137  Black or African American       Full Time  Female  2008-11-24  2013-07-17  \n",
       "196  Black or African American       Full Time  Female  1992-08-31  2008-03-08  \n",
       "228  Black or African American       Full Time  Female  1985-04-15  2009-07-25  "
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c1 = employee['RACE'] == 'Black or African American'\n",
    "c2 = employee['GENDER'] == 'Female'\n",
    "c3 = employee['DEPARTMENT'] == 'Houston Police Department-HPD'\n",
    "c_all = c1 & c2 & c3\n",
    "employee[c_all].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 9\n",
    "<span  style=\"color:green; font-size:16px\">Find the females that have a salary over 100,000 OR males with salary under 50,000</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>POSITION_TITLE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>BASE_SALARY</th>\n",
       "      <th>RACE</th>\n",
       "      <th>EMPLOYMENT_TYPE</th>\n",
       "      <th>GENDER</th>\n",
       "      <th>HIRE_DATE</th>\n",
       "      <th>JOB_DATE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>ASSISTANT DIRECTOR (EX LVL)</td>\n",
       "      <td>Municipal Courts Department</td>\n",
       "      <td>121862.0</td>\n",
       "      <td>Hispanic/Latino</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Female</td>\n",
       "      <td>2006-06-12</td>\n",
       "      <td>2012-10-13</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>POLICE OFFICER</td>\n",
       "      <td>Houston Police Department-HPD</td>\n",
       "      <td>45279.0</td>\n",
       "      <td>White</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Male</td>\n",
       "      <td>2015-02-03</td>\n",
       "      <td>2015-02-03</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>CARPENTER</td>\n",
       "      <td>Houston Airport System (HAS)</td>\n",
       "      <td>42390.0</td>\n",
       "      <td>White</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Male</td>\n",
       "      <td>2013-11-04</td>\n",
       "      <td>2013-11-04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>AIRPORT OPERATIONS COORDINATOR</td>\n",
       "      <td>Houston Airport System (HAS)</td>\n",
       "      <td>44616.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Male</td>\n",
       "      <td>2016-03-14</td>\n",
       "      <td>2016-03-14</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>CUSTOMER SERVICE REPRESENTATIVE I</td>\n",
       "      <td>Public Works &amp; Engineering-PWE</td>\n",
       "      <td>30347.0</td>\n",
       "      <td>Black or African American</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Male</td>\n",
       "      <td>2015-11-16</td>\n",
       "      <td>2015-11-16</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       POSITION_TITLE                      DEPARTMENT  \\\n",
       "0         ASSISTANT DIRECTOR (EX LVL)     Municipal Courts Department   \n",
       "2                      POLICE OFFICER   Houston Police Department-HPD   \n",
       "7                           CARPENTER    Houston Airport System (HAS)   \n",
       "9      AIRPORT OPERATIONS COORDINATOR    Houston Airport System (HAS)   \n",
       "12  CUSTOMER SERVICE REPRESENTATIVE I  Public Works & Engineering-PWE   \n",
       "\n",
       "    BASE_SALARY                       RACE EMPLOYMENT_TYPE  GENDER  \\\n",
       "0      121862.0            Hispanic/Latino       Full Time  Female   \n",
       "2       45279.0                      White       Full Time    Male   \n",
       "7       42390.0                      White       Full Time    Male   \n",
       "9       44616.0                        NaN       Full Time    Male   \n",
       "12      30347.0  Black or African American       Full Time    Male   \n",
       "\n",
       "     HIRE_DATE    JOB_DATE  \n",
       "0   2006-06-12  2012-10-13  \n",
       "2   2015-02-03  2015-02-03  \n",
       "7   2013-11-04  2013-11-04  \n",
       "9   2016-03-14  2016-03-14  \n",
       "12  2015-11-16  2015-11-16  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c1 = (employee['GENDER'] == 'Female') & (employee['BASE_SALARY'] > 100000)\n",
    "c2 = (employee['GENDER'] == 'Male') & (employee['BASE_SALARY'] < 50000)\n",
    "c_all = c1 | c2\n",
    "employee[c_all].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 10\n",
    "<span  style=\"color:green; font-size:16px\">Find the females in the following departments with salary over 60,000 (Parks & Recreation, Solid Waste Management, Fleet Management Department, Library)  </span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>POSITION_TITLE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>BASE_SALARY</th>\n",
       "      <th>RACE</th>\n",
       "      <th>EMPLOYMENT_TYPE</th>\n",
       "      <th>GENDER</th>\n",
       "      <th>HIRE_DATE</th>\n",
       "      <th>JOB_DATE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>249</th>\n",
       "      <td>STAFF ANALYST</td>\n",
       "      <td>Solid Waste Management</td>\n",
       "      <td>75041.0</td>\n",
       "      <td>Hispanic/Latino</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Female</td>\n",
       "      <td>1992-10-21</td>\n",
       "      <td>2015-07-18</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>412</th>\n",
       "      <td>ADMINISTRATIVE COORDINATOR</td>\n",
       "      <td>Library</td>\n",
       "      <td>79302.0</td>\n",
       "      <td>Hispanic/Latino</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Female</td>\n",
       "      <td>2003-12-22</td>\n",
       "      <td>2005-04-02</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>476</th>\n",
       "      <td>ADMINISTRATIVE SUPERVISOR</td>\n",
       "      <td>Library</td>\n",
       "      <td>60632.0</td>\n",
       "      <td>Black or African American</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Female</td>\n",
       "      <td>1993-05-10</td>\n",
       "      <td>2014-11-08</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>892</th>\n",
       "      <td>LIBRARIAN III</td>\n",
       "      <td>Library</td>\n",
       "      <td>61454.0</td>\n",
       "      <td>White</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Female</td>\n",
       "      <td>1998-11-02</td>\n",
       "      <td>2002-06-15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1165</th>\n",
       "      <td>DEPUTY ASSISTANT DIRECTOR (EXECUTIVE LEV</td>\n",
       "      <td>Library</td>\n",
       "      <td>107763.0</td>\n",
       "      <td>Black or African American</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Female</td>\n",
       "      <td>1993-11-16</td>\n",
       "      <td>2014-03-15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1484</th>\n",
       "      <td>SENIOR STAFF ANALYST (EXECUTIVE LEVEL)</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>83916.0</td>\n",
       "      <td>Hispanic/Latino</td>\n",
       "      <td>Full Time</td>\n",
       "      <td>Female</td>\n",
       "      <td>1999-07-26</td>\n",
       "      <td>2013-08-31</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                POSITION_TITLE              DEPARTMENT  \\\n",
       "249                              STAFF ANALYST  Solid Waste Management   \n",
       "412                 ADMINISTRATIVE COORDINATOR                 Library   \n",
       "476                  ADMINISTRATIVE SUPERVISOR                 Library   \n",
       "892                              LIBRARIAN III                 Library   \n",
       "1165  DEPUTY ASSISTANT DIRECTOR (EXECUTIVE LEV                 Library   \n",
       "1484    SENIOR STAFF ANALYST (EXECUTIVE LEVEL)      Parks & Recreation   \n",
       "\n",
       "      BASE_SALARY                       RACE EMPLOYMENT_TYPE  GENDER  \\\n",
       "249       75041.0            Hispanic/Latino       Full Time  Female   \n",
       "412       79302.0            Hispanic/Latino       Full Time  Female   \n",
       "476       60632.0  Black or African American       Full Time  Female   \n",
       "892       61454.0                      White       Full Time  Female   \n",
       "1165     107763.0  Black or African American       Full Time  Female   \n",
       "1484      83916.0            Hispanic/Latino       Full Time  Female   \n",
       "\n",
       "       HIRE_DATE    JOB_DATE  \n",
       "249   1992-10-21  2015-07-18  \n",
       "412   2003-12-22  2005-04-02  \n",
       "476   1993-05-10  2014-11-08  \n",
       "892   1998-11-02  2002-06-15  \n",
       "1165  1993-11-16  2014-03-15  \n",
       "1484  1999-07-26  2013-08-31  "
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "deps = ['Parks & Recreation', 'Solid Waste Management', 'Fleet Management Department', 'Library']\n",
    "c1 = employee['DEPARTMENT'].isin(deps) \n",
    "c2 = employee['GENDER'] == 'Female'\n",
    "c3 = employee['BASE_SALARY'] > 60000\n",
    "\n",
    "employee[c1 & c2 & c3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 11\n",
    "<span  style=\"color:green; font-size:16px\">Find all the males with salary over 100,000. Return only the race, gender and salary columns</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>RACE</th>\n",
       "      <th>GENDER</th>\n",
       "      <th>BASE_SALARY</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>White</td>\n",
       "      <td>Male</td>\n",
       "      <td>107962.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>Black or African American</td>\n",
       "      <td>Male</td>\n",
       "      <td>180416.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>43</th>\n",
       "      <td>Hispanic/Latino</td>\n",
       "      <td>Male</td>\n",
       "      <td>165216.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>169</th>\n",
       "      <td>White</td>\n",
       "      <td>Male</td>\n",
       "      <td>120916.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>178</th>\n",
       "      <td>White</td>\n",
       "      <td>Male</td>\n",
       "      <td>210588.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                          RACE GENDER  BASE_SALARY\n",
       "8                        White   Male     107962.0\n",
       "11   Black or African American   Male     180416.0\n",
       "43             Hispanic/Latino   Male     165216.0\n",
       "169                      White   Male     120916.0\n",
       "178                      White   Male     210588.0"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "criteria = (employee['GENDER'] == 'Male') & (employee['BASE_SALARY'] > 100000)\n",
    "employee.loc[criteria, ['RACE', 'GENDER', 'BASE_SALARY']].head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 12\n",
    "<span  style=\"color:green; font-size:16px\">Select all salaries as a Series in a separate variable. From this series select all salaries under 25,000</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "454    24960.0\n",
       "Name: BASE_SALARY, dtype: float64"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = employee['BASE_SALARY']\n",
    "s[s < 25000]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 13\n",
    "<span  style=\"color:green; font-size:16px\">Get the same exact result as exercise 11, but make your selection from the employee DataFrame. Use only a single line of code</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "454    24960.0\n",
       "Name: BASE_SALARY, dtype: float64"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "employee.loc[employee['BASE_SALARY'] < 25000, 'BASE_SALARY']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "collapsed": true
   },
   "source": [
    "# Part 3: Assigning subsets of data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY\n",
       "Tom         Male  White         Engineering                23  107962\n",
       "Niko        Male  Black         Engineering                 1   30347\n",
       "Penelope  Female  White         Engineering                12   60258\n",
       "Aria      Female  Black         Engineering                 8   43618\n",
       "Sofia     Female  Black  Parks & Recreation                23   26125\n",
       "Dean        Male  Black  Parks & Recreation                 3   33592\n",
       "Zach        Male  White  Parks & Recreation                 4   37565"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('../../data/employee_sample.csv', index_col=0)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "def style_diff(df, df_orig):\n",
    "    style = {True: '', \n",
    "             False: 'color: red; background-color: yellow'}\n",
    "    df_style = (df == df_orig).replace(style)\n",
    "    return df.style.apply(lambda x: df_style, axis=None)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 1\n",
    "<span  style=\"color:green; font-size:16px\"> Create a Series with the index equal to the same values in **`df`** but in a different order. Make the values of the Series integers representing the employee's age ranging somewhere from 20 to 65. Create a new column **`AGE`**. Does the order of the index matter?</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Aria        25\n",
       "Niko        30\n",
       "Tom         40\n",
       "Zach        50\n",
       "Penelope    35\n",
       "Sofia       36\n",
       "Dean        44\n",
       "dtype: int64"
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "s = pd.Series(data=[25, 30, 40, 50, 35, 36, 44],\n",
    "              index=['Aria', 'Niko', 'Tom', 'Zach', 'Penelope', 'Sofia', 'Dean'])\n",
    "s"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "      <th>AGE</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "      <td>40</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "      <td>30</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "      <td>35</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "      <td>25</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "      <td>36</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "      <td>44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "      <td>50</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY  AGE\n",
       "Tom         Male  White         Engineering                23  107962   40\n",
       "Niko        Male  Black         Engineering                 1   30347   30\n",
       "Penelope  Female  White         Engineering                12   60258   35\n",
       "Aria      Female  Black         Engineering                 8   43618   25\n",
       "Sofia     Female  Black  Parks & Recreation                23   26125   36\n",
       "Dean        Male  Black  Parks & Recreation                 3   33592   44\n",
       "Zach        Male  White  Parks & Recreation                 4   37565   50"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['AGE'] = s\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The order of the index does not matter. They automatically align on their index."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 2\n",
    "<span  style=\"color:green; font-size:16px\"> Create a new column **`BONUS`** equal to 0 for everyone</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "      <th>AGE</th>\n",
       "      <th>BONUS</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "      <td>40</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "      <td>35</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "      <td>25</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "      <td>36</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "      <td>44</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "      <td>50</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY  AGE  \\\n",
       "Tom         Male  White         Engineering                23  107962   40   \n",
       "Niko        Male  Black         Engineering                 1   30347   30   \n",
       "Penelope  Female  White         Engineering                12   60258   35   \n",
       "Aria      Female  Black         Engineering                 8   43618   25   \n",
       "Sofia     Female  Black  Parks & Recreation                23   26125   36   \n",
       "Dean        Male  Black  Parks & Recreation                 3   33592   44   \n",
       "Zach        Male  White  Parks & Recreation                 4   37565   50   \n",
       "\n",
       "          BONUS  \n",
       "Tom           0  \n",
       "Niko          0  \n",
       "Penelope      0  \n",
       "Aria          0  \n",
       "Sofia         0  \n",
       "Dean          0  \n",
       "Zach          0  "
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df['BONUS'] = 0\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 3\n",
    "<span  style=\"color:green; font-size:16px\"> Change the **`BONUS`** column so that everyone with more than 10 years of experience get $10,000. Use the **`style_diff`** function to display the results.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_60943dca_e061_11e7_ad22_b8e85647e68crow0_col6 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_60943dca_e061_11e7_ad22_b8e85647e68crow2_col6 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_60943dca_e061_11e7_ad22_b8e85647e68crow4_col6 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }</style>  \n",
       "<table id=\"T_60943dca_e061_11e7_ad22_b8e85647e68c\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >GENDER</th> \n",
       "        <th class=\"col_heading level0 col1\" >RACE</th> \n",
       "        <th class=\"col_heading level0 col2\" >DEPARTMENT</th> \n",
       "        <th class=\"col_heading level0 col3\" >YEARS EXPERIENCE</th> \n",
       "        <th class=\"col_heading level0 col4\" >SALARY</th> \n",
       "        <th class=\"col_heading level0 col5\" >AGE</th> \n",
       "        <th class=\"col_heading level0 col6\" >BONUS</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_60943dca_e061_11e7_ad22_b8e85647e68clevel0_row0\" class=\"row_heading level0 row0\" >Tom</th> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow0_col0\" class=\"data row0 col0\" >Male</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow0_col1\" class=\"data row0 col1\" >White</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow0_col2\" class=\"data row0 col2\" >Engineering</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow0_col3\" class=\"data row0 col3\" >23</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow0_col4\" class=\"data row0 col4\" >107962</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow0_col5\" class=\"data row0 col5\" >40</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow0_col6\" class=\"data row0 col6\" >10000</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60943dca_e061_11e7_ad22_b8e85647e68clevel0_row1\" class=\"row_heading level0 row1\" >Niko</th> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow1_col0\" class=\"data row1 col0\" >Male</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow1_col1\" class=\"data row1 col1\" >Black</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow1_col2\" class=\"data row1 col2\" >Engineering</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow1_col3\" class=\"data row1 col3\" >1</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow1_col4\" class=\"data row1 col4\" >30347</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow1_col5\" class=\"data row1 col5\" >30</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow1_col6\" class=\"data row1 col6\" >0</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60943dca_e061_11e7_ad22_b8e85647e68clevel0_row2\" class=\"row_heading level0 row2\" >Penelope</th> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow2_col0\" class=\"data row2 col0\" >Female</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow2_col1\" class=\"data row2 col1\" >White</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow2_col2\" class=\"data row2 col2\" >Engineering</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow2_col3\" class=\"data row2 col3\" >12</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow2_col4\" class=\"data row2 col4\" >60258</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow2_col5\" class=\"data row2 col5\" >35</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow2_col6\" class=\"data row2 col6\" >10000</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60943dca_e061_11e7_ad22_b8e85647e68clevel0_row3\" class=\"row_heading level0 row3\" >Aria</th> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow3_col0\" class=\"data row3 col0\" >Female</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow3_col1\" class=\"data row3 col1\" >Black</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow3_col2\" class=\"data row3 col2\" >Engineering</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow3_col3\" class=\"data row3 col3\" >8</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow3_col4\" class=\"data row3 col4\" >43618</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow3_col5\" class=\"data row3 col5\" >25</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow3_col6\" class=\"data row3 col6\" >0</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60943dca_e061_11e7_ad22_b8e85647e68clevel0_row4\" class=\"row_heading level0 row4\" >Sofia</th> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow4_col0\" class=\"data row4 col0\" >Female</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow4_col1\" class=\"data row4 col1\" >Black</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow4_col2\" class=\"data row4 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow4_col3\" class=\"data row4 col3\" >23</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow4_col4\" class=\"data row4 col4\" >26125</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow4_col5\" class=\"data row4 col5\" >36</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow4_col6\" class=\"data row4 col6\" >10000</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60943dca_e061_11e7_ad22_b8e85647e68clevel0_row5\" class=\"row_heading level0 row5\" >Dean</th> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow5_col0\" class=\"data row5 col0\" >Male</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow5_col1\" class=\"data row5 col1\" >Black</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow5_col2\" class=\"data row5 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow5_col3\" class=\"data row5 col3\" >3</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow5_col4\" class=\"data row5 col4\" >33592</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow5_col5\" class=\"data row5 col5\" >44</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow5_col6\" class=\"data row5 col6\" >0</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60943dca_e061_11e7_ad22_b8e85647e68clevel0_row6\" class=\"row_heading level0 row6\" >Zach</th> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow6_col0\" class=\"data row6 col0\" >Male</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow6_col1\" class=\"data row6 col1\" >White</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow6_col2\" class=\"data row6 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow6_col3\" class=\"data row6 col3\" >4</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow6_col4\" class=\"data row6 col4\" >37565</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow6_col5\" class=\"data row6 col5\" >50</td> \n",
       "        <td id=\"T_60943dca_e061_11e7_ad22_b8e85647e68crow6_col6\" class=\"data row6 col6\" >0</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x10d912198>"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_orig = df.copy()\n",
    "df.loc[df['YEARS EXPERIENCE'] > 10, 'BONUS'] = 10000\n",
    "style_diff(df, df_orig)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 4\n",
    "<span  style=\"color:green; font-size:16px\"> Create a new column **`TOTAL SALARY`** that is 10% higher than the current **`SALARY`** column and add the bonus on top of that as well. Use **`.loc`** on the left-hand side and NOT *just the indexing operator*. Make the data type **`TOTAL SALARY`** an integer.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "      <th>AGE</th>\n",
       "      <th>BONUS</th>\n",
       "      <th>TOTAL SALARY</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "      <td>40</td>\n",
       "      <td>10000</td>\n",
       "      <td>128758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>33381</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "      <td>35</td>\n",
       "      <td>10000</td>\n",
       "      <td>76283</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "      <td>25</td>\n",
       "      <td>0</td>\n",
       "      <td>47979</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "      <td>36</td>\n",
       "      <td>10000</td>\n",
       "      <td>38737</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "      <td>44</td>\n",
       "      <td>0</td>\n",
       "      <td>36951</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "      <td>50</td>\n",
       "      <td>0</td>\n",
       "      <td>41321</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY  AGE  \\\n",
       "Tom         Male  White         Engineering                23  107962   40   \n",
       "Niko        Male  Black         Engineering                 1   30347   30   \n",
       "Penelope  Female  White         Engineering                12   60258   35   \n",
       "Aria      Female  Black         Engineering                 8   43618   25   \n",
       "Sofia     Female  Black  Parks & Recreation                23   26125   36   \n",
       "Dean        Male  Black  Parks & Recreation                 3   33592   44   \n",
       "Zach        Male  White  Parks & Recreation                 4   37565   50   \n",
       "\n",
       "          BONUS  TOTAL SALARY  \n",
       "Tom       10000        128758  \n",
       "Niko          0         33381  \n",
       "Penelope  10000         76283  \n",
       "Aria          0         47979  \n",
       "Sofia     10000         38737  \n",
       "Dean          0         36951  \n",
       "Zach          0         41321  "
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[:, 'TOTAL SALARY'] = df['SALARY'] * 1.1 + df['BONUS']\n",
    "df.loc[:, 'TOTAL SALARY'] = df.loc[:, 'TOTAL SALARY'].astype(int)\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>GENDER</th>\n",
       "      <th>RACE</th>\n",
       "      <th>DEPARTMENT</th>\n",
       "      <th>YEARS EXPERIENCE</th>\n",
       "      <th>SALARY</th>\n",
       "      <th>AGE</th>\n",
       "      <th>BONUS</th>\n",
       "      <th>TOTAL SALARY</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Tom</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>23</td>\n",
       "      <td>107962</td>\n",
       "      <td>40</td>\n",
       "      <td>10000</td>\n",
       "      <td>128758</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>1</td>\n",
       "      <td>30347</td>\n",
       "      <td>30</td>\n",
       "      <td>0</td>\n",
       "      <td>33381</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>Female</td>\n",
       "      <td>White</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>12</td>\n",
       "      <td>60258</td>\n",
       "      <td>35</td>\n",
       "      <td>10000</td>\n",
       "      <td>76283</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aria</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Engineering</td>\n",
       "      <td>8</td>\n",
       "      <td>43618</td>\n",
       "      <td>25</td>\n",
       "      <td>0</td>\n",
       "      <td>47979</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Sofia</th>\n",
       "      <td>Female</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>23</td>\n",
       "      <td>26125</td>\n",
       "      <td>36</td>\n",
       "      <td>10000</td>\n",
       "      <td>38737</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>Male</td>\n",
       "      <td>Black</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>3</td>\n",
       "      <td>33592</td>\n",
       "      <td>44</td>\n",
       "      <td>0</td>\n",
       "      <td>36951</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Zach</th>\n",
       "      <td>Male</td>\n",
       "      <td>White</td>\n",
       "      <td>Parks &amp; Recreation</td>\n",
       "      <td>4</td>\n",
       "      <td>37565</td>\n",
       "      <td>50</td>\n",
       "      <td>0</td>\n",
       "      <td>41321</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          GENDER   RACE          DEPARTMENT  YEARS EXPERIENCE  SALARY  AGE  \\\n",
       "Tom         Male  White         Engineering                23  107962   40   \n",
       "Niko        Male  Black         Engineering                 1   30347   30   \n",
       "Penelope  Female  White         Engineering                12   60258   35   \n",
       "Aria      Female  Black         Engineering                 8   43618   25   \n",
       "Sofia     Female  Black  Parks & Recreation                23   26125   36   \n",
       "Dean        Male  Black  Parks & Recreation                 3   33592   44   \n",
       "Zach        Male  White  Parks & Recreation                 4   37565   50   \n",
       "\n",
       "          BONUS  TOTAL SALARY  \n",
       "Tom       10000        128758  \n",
       "Niko          0         33381  \n",
       "Penelope  10000         76283  \n",
       "Aria          0         47979  \n",
       "Sofia     10000         38737  \n",
       "Dean          0         36951  \n",
       "Zach          0         41321  "
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# in one line\n",
    "df.loc[:, 'TOTAL SALARY'] = (df['SALARY'] * 1.1 + df['BONUS']).astype(int)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 5\n",
    "<span  style=\"color:green; font-size:16px\"> Set Aria's department to 'Police'. Highlight the change</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_60a3f58a_e061_11e7_a44c_b8e85647e68crow3_col2 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }</style>  \n",
       "<table id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68c\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >GENDER</th> \n",
       "        <th class=\"col_heading level0 col1\" >RACE</th> \n",
       "        <th class=\"col_heading level0 col2\" >DEPARTMENT</th> \n",
       "        <th class=\"col_heading level0 col3\" >YEARS EXPERIENCE</th> \n",
       "        <th class=\"col_heading level0 col4\" >SALARY</th> \n",
       "        <th class=\"col_heading level0 col5\" >AGE</th> \n",
       "        <th class=\"col_heading level0 col6\" >BONUS</th> \n",
       "        <th class=\"col_heading level0 col7\" >TOTAL SALARY</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68clevel0_row0\" class=\"row_heading level0 row0\" >Tom</th> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow0_col0\" class=\"data row0 col0\" >Male</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow0_col1\" class=\"data row0 col1\" >White</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow0_col2\" class=\"data row0 col2\" >Engineering</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow0_col3\" class=\"data row0 col3\" >23</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow0_col4\" class=\"data row0 col4\" >107962</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow0_col5\" class=\"data row0 col5\" >40</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow0_col6\" class=\"data row0 col6\" >10000</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow0_col7\" class=\"data row0 col7\" >128758</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68clevel0_row1\" class=\"row_heading level0 row1\" >Niko</th> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow1_col0\" class=\"data row1 col0\" >Male</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow1_col1\" class=\"data row1 col1\" >Black</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow1_col2\" class=\"data row1 col2\" >Engineering</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow1_col3\" class=\"data row1 col3\" >1</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow1_col4\" class=\"data row1 col4\" >30347</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow1_col5\" class=\"data row1 col5\" >30</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow1_col6\" class=\"data row1 col6\" >0</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow1_col7\" class=\"data row1 col7\" >33381</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68clevel0_row2\" class=\"row_heading level0 row2\" >Penelope</th> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow2_col0\" class=\"data row2 col0\" >Female</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow2_col1\" class=\"data row2 col1\" >White</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow2_col2\" class=\"data row2 col2\" >Engineering</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow2_col3\" class=\"data row2 col3\" >12</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow2_col4\" class=\"data row2 col4\" >60258</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow2_col5\" class=\"data row2 col5\" >35</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow2_col6\" class=\"data row2 col6\" >10000</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow2_col7\" class=\"data row2 col7\" >76283</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68clevel0_row3\" class=\"row_heading level0 row3\" >Aria</th> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow3_col0\" class=\"data row3 col0\" >Female</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow3_col1\" class=\"data row3 col1\" >Black</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow3_col2\" class=\"data row3 col2\" >Police</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow3_col3\" class=\"data row3 col3\" >8</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow3_col4\" class=\"data row3 col4\" >43618</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow3_col5\" class=\"data row3 col5\" >25</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow3_col6\" class=\"data row3 col6\" >0</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow3_col7\" class=\"data row3 col7\" >47979</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68clevel0_row4\" class=\"row_heading level0 row4\" >Sofia</th> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow4_col0\" class=\"data row4 col0\" >Female</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow4_col1\" class=\"data row4 col1\" >Black</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow4_col2\" class=\"data row4 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow4_col3\" class=\"data row4 col3\" >23</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow4_col4\" class=\"data row4 col4\" >26125</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow4_col5\" class=\"data row4 col5\" >36</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow4_col6\" class=\"data row4 col6\" >10000</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow4_col7\" class=\"data row4 col7\" >38737</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68clevel0_row5\" class=\"row_heading level0 row5\" >Dean</th> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow5_col0\" class=\"data row5 col0\" >Male</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow5_col1\" class=\"data row5 col1\" >Black</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow5_col2\" class=\"data row5 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow5_col3\" class=\"data row5 col3\" >3</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow5_col4\" class=\"data row5 col4\" >33592</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow5_col5\" class=\"data row5 col5\" >44</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow5_col6\" class=\"data row5 col6\" >0</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow5_col7\" class=\"data row5 col7\" >36951</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68clevel0_row6\" class=\"row_heading level0 row6\" >Zach</th> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow6_col0\" class=\"data row6 col0\" >Male</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow6_col1\" class=\"data row6 col1\" >White</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow6_col2\" class=\"data row6 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow6_col3\" class=\"data row6 col3\" >4</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow6_col4\" class=\"data row6 col4\" >37565</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow6_col5\" class=\"data row6 col5\" >50</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow6_col6\" class=\"data row6 col6\" >0</td> \n",
       "        <td id=\"T_60a3f58a_e061_11e7_a44c_b8e85647e68crow6_col7\" class=\"data row6 col7\" >41321</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x111c066d8>"
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_orig = df.copy()\n",
    "df.loc['Aria', 'DEPARTMENT'] = 'Police'\n",
    "style_diff(df, df_orig)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 6\n",
    "<span  style=\"color:green; font-size:16px\"> Give all the white engineers a salary raise of \\$10,000 and all the black Parks & Recreation employees a decrease in salary by \\$10,000. Highlight the change.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_60a94d0a_e061_11e7_9c56_b8e85647e68crow0_col4 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_60a94d0a_e061_11e7_9c56_b8e85647e68crow2_col4 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_60a94d0a_e061_11e7_9c56_b8e85647e68crow4_col4 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_60a94d0a_e061_11e7_9c56_b8e85647e68crow5_col4 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }</style>  \n",
       "<table id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68c\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >GENDER</th> \n",
       "        <th class=\"col_heading level0 col1\" >RACE</th> \n",
       "        <th class=\"col_heading level0 col2\" >DEPARTMENT</th> \n",
       "        <th class=\"col_heading level0 col3\" >YEARS EXPERIENCE</th> \n",
       "        <th class=\"col_heading level0 col4\" >SALARY</th> \n",
       "        <th class=\"col_heading level0 col5\" >AGE</th> \n",
       "        <th class=\"col_heading level0 col6\" >BONUS</th> \n",
       "        <th class=\"col_heading level0 col7\" >TOTAL SALARY</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68clevel0_row0\" class=\"row_heading level0 row0\" >Tom</th> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow0_col0\" class=\"data row0 col0\" >Male</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow0_col1\" class=\"data row0 col1\" >White</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow0_col2\" class=\"data row0 col2\" >Engineering</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow0_col3\" class=\"data row0 col3\" >23</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow0_col4\" class=\"data row0 col4\" >117962</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow0_col5\" class=\"data row0 col5\" >40</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow0_col6\" class=\"data row0 col6\" >10000</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow0_col7\" class=\"data row0 col7\" >128758</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68clevel0_row1\" class=\"row_heading level0 row1\" >Niko</th> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow1_col0\" class=\"data row1 col0\" >Male</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow1_col1\" class=\"data row1 col1\" >Black</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow1_col2\" class=\"data row1 col2\" >Engineering</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow1_col3\" class=\"data row1 col3\" >1</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow1_col4\" class=\"data row1 col4\" >30347</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow1_col5\" class=\"data row1 col5\" >30</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow1_col6\" class=\"data row1 col6\" >0</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow1_col7\" class=\"data row1 col7\" >33381</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68clevel0_row2\" class=\"row_heading level0 row2\" >Penelope</th> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow2_col0\" class=\"data row2 col0\" >Female</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow2_col1\" class=\"data row2 col1\" >White</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow2_col2\" class=\"data row2 col2\" >Engineering</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow2_col3\" class=\"data row2 col3\" >12</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow2_col4\" class=\"data row2 col4\" >70258</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow2_col5\" class=\"data row2 col5\" >35</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow2_col6\" class=\"data row2 col6\" >10000</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow2_col7\" class=\"data row2 col7\" >76283</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68clevel0_row3\" class=\"row_heading level0 row3\" >Aria</th> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow3_col0\" class=\"data row3 col0\" >Female</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow3_col1\" class=\"data row3 col1\" >Black</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow3_col2\" class=\"data row3 col2\" >Police</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow3_col3\" class=\"data row3 col3\" >8</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow3_col4\" class=\"data row3 col4\" >43618</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow3_col5\" class=\"data row3 col5\" >25</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow3_col6\" class=\"data row3 col6\" >0</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow3_col7\" class=\"data row3 col7\" >47979</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68clevel0_row4\" class=\"row_heading level0 row4\" >Sofia</th> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow4_col0\" class=\"data row4 col0\" >Female</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow4_col1\" class=\"data row4 col1\" >Black</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow4_col2\" class=\"data row4 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow4_col3\" class=\"data row4 col3\" >23</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow4_col4\" class=\"data row4 col4\" >16125</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow4_col5\" class=\"data row4 col5\" >36</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow4_col6\" class=\"data row4 col6\" >10000</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow4_col7\" class=\"data row4 col7\" >38737</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68clevel0_row5\" class=\"row_heading level0 row5\" >Dean</th> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow5_col0\" class=\"data row5 col0\" >Male</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow5_col1\" class=\"data row5 col1\" >Black</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow5_col2\" class=\"data row5 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow5_col3\" class=\"data row5 col3\" >3</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow5_col4\" class=\"data row5 col4\" >23592</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow5_col5\" class=\"data row5 col5\" >44</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow5_col6\" class=\"data row5 col6\" >0</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow5_col7\" class=\"data row5 col7\" >36951</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68clevel0_row6\" class=\"row_heading level0 row6\" >Zach</th> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow6_col0\" class=\"data row6 col0\" >Male</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow6_col1\" class=\"data row6 col1\" >White</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow6_col2\" class=\"data row6 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow6_col3\" class=\"data row6 col3\" >4</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow6_col4\" class=\"data row6 col4\" >37565</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow6_col5\" class=\"data row6 col5\" >50</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow6_col6\" class=\"data row6 col6\" >0</td> \n",
       "        <td id=\"T_60a94d0a_e061_11e7_9c56_b8e85647e68crow6_col7\" class=\"data row6 col7\" >41321</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x11238ef60>"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_orig = df.copy()\n",
    "white_eng = (df['RACE'] == 'White') & (df['DEPARTMENT'] == 'Engineering')\n",
    "black_pr = (df['RACE'] == 'Black') & (df['DEPARTMENT'] == 'Parks & Recreation')\n",
    "df.loc[white_eng, 'SALARY'] += 10000\n",
    "df.loc[black_pr, 'SALARY'] -= 10000\n",
    "style_diff(df, df_orig)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 7\n",
    "<span  style=\"color:green; font-size:16px\"> Use **`.iloc`** to change the age of the employees with integer location 3 and 5 to 60 and 65 respectively. Highlight the change.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<style  type=\"text/css\" >\n",
       "    #T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow3_col5 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }    #T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow5_col5 {\n",
       "            color:  red;\n",
       "             background-color:  yellow;\n",
       "        }</style>  \n",
       "<table id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68c\" > \n",
       "<thead>    <tr> \n",
       "        <th class=\"blank level0\" ></th> \n",
       "        <th class=\"col_heading level0 col0\" >GENDER</th> \n",
       "        <th class=\"col_heading level0 col1\" >RACE</th> \n",
       "        <th class=\"col_heading level0 col2\" >DEPARTMENT</th> \n",
       "        <th class=\"col_heading level0 col3\" >YEARS EXPERIENCE</th> \n",
       "        <th class=\"col_heading level0 col4\" >SALARY</th> \n",
       "        <th class=\"col_heading level0 col5\" >AGE</th> \n",
       "        <th class=\"col_heading level0 col6\" >BONUS</th> \n",
       "        <th class=\"col_heading level0 col7\" >TOTAL SALARY</th> \n",
       "    </tr></thead> \n",
       "<tbody>    <tr> \n",
       "        <th id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68clevel0_row0\" class=\"row_heading level0 row0\" >Tom</th> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow0_col0\" class=\"data row0 col0\" >Male</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow0_col1\" class=\"data row0 col1\" >White</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow0_col2\" class=\"data row0 col2\" >Engineering</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow0_col3\" class=\"data row0 col3\" >23</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow0_col4\" class=\"data row0 col4\" >117962</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow0_col5\" class=\"data row0 col5\" >40</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow0_col6\" class=\"data row0 col6\" >10000</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow0_col7\" class=\"data row0 col7\" >128758</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68clevel0_row1\" class=\"row_heading level0 row1\" >Niko</th> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow1_col0\" class=\"data row1 col0\" >Male</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow1_col1\" class=\"data row1 col1\" >Black</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow1_col2\" class=\"data row1 col2\" >Engineering</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow1_col3\" class=\"data row1 col3\" >1</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow1_col4\" class=\"data row1 col4\" >30347</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow1_col5\" class=\"data row1 col5\" >30</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow1_col6\" class=\"data row1 col6\" >0</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow1_col7\" class=\"data row1 col7\" >33381</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68clevel0_row2\" class=\"row_heading level0 row2\" >Penelope</th> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow2_col0\" class=\"data row2 col0\" >Female</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow2_col1\" class=\"data row2 col1\" >White</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow2_col2\" class=\"data row2 col2\" >Engineering</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow2_col3\" class=\"data row2 col3\" >12</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow2_col4\" class=\"data row2 col4\" >70258</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow2_col5\" class=\"data row2 col5\" >35</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow2_col6\" class=\"data row2 col6\" >10000</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow2_col7\" class=\"data row2 col7\" >76283</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68clevel0_row3\" class=\"row_heading level0 row3\" >Aria</th> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow3_col0\" class=\"data row3 col0\" >Female</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow3_col1\" class=\"data row3 col1\" >Black</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow3_col2\" class=\"data row3 col2\" >Police</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow3_col3\" class=\"data row3 col3\" >8</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow3_col4\" class=\"data row3 col4\" >43618</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow3_col5\" class=\"data row3 col5\" >60</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow3_col6\" class=\"data row3 col6\" >0</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow3_col7\" class=\"data row3 col7\" >47979</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68clevel0_row4\" class=\"row_heading level0 row4\" >Sofia</th> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow4_col0\" class=\"data row4 col0\" >Female</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow4_col1\" class=\"data row4 col1\" >Black</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow4_col2\" class=\"data row4 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow4_col3\" class=\"data row4 col3\" >23</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow4_col4\" class=\"data row4 col4\" >16125</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow4_col5\" class=\"data row4 col5\" >36</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow4_col6\" class=\"data row4 col6\" >10000</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow4_col7\" class=\"data row4 col7\" >38737</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68clevel0_row5\" class=\"row_heading level0 row5\" >Dean</th> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow5_col0\" class=\"data row5 col0\" >Male</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow5_col1\" class=\"data row5 col1\" >Black</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow5_col2\" class=\"data row5 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow5_col3\" class=\"data row5 col3\" >3</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow5_col4\" class=\"data row5 col4\" >23592</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow5_col5\" class=\"data row5 col5\" >65</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow5_col6\" class=\"data row5 col6\" >0</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow5_col7\" class=\"data row5 col7\" >36951</td> \n",
       "    </tr>    <tr> \n",
       "        <th id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68clevel0_row6\" class=\"row_heading level0 row6\" >Zach</th> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow6_col0\" class=\"data row6 col0\" >Male</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow6_col1\" class=\"data row6 col1\" >White</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow6_col2\" class=\"data row6 col2\" >Parks & Recreation</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow6_col3\" class=\"data row6 col3\" >4</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow6_col4\" class=\"data row6 col4\" >37565</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow6_col5\" class=\"data row6 col5\" >50</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow6_col6\" class=\"data row6 col6\" >0</td> \n",
       "        <td id=\"T_60ad36fe_e061_11e7_b0b4_b8e85647e68crow6_col7\" class=\"data row6 col7\" >41321</td> \n",
       "    </tr></tbody> \n",
       "</table> "
      ],
      "text/plain": [
       "<pandas.io.formats.style.Styler at 0x111c06400>"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_orig = df.copy()\n",
    "df.iloc[[3, 5], -3] = [60, 65]\n",
    "style_diff(df, df_orig)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Part 4: How NOT to select subsets of data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 1\n",
    "<span  style=\"color:green; font-size:16px\"> Create a ten item list and then use chained indexing to select the items from 2 to the end and then from this subset, the first three items</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3, 4, 5]"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n",
    "a[2:][:3]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 2\n",
    "<span  style=\"color:green; font-size:16px\"> Get the same result from example 1 with just a single call to the indexing operator.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[3, 4, 5]"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a[2:5]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Use the following DataFrame for the next several questions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>state</th>\n",
       "      <th>color</th>\n",
       "      <th>food</th>\n",
       "      <th>age</th>\n",
       "      <th>height</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Jane</th>\n",
       "      <td>NY</td>\n",
       "      <td>blue</td>\n",
       "      <td>Steak</td>\n",
       "      <td>30</td>\n",
       "      <td>165</td>\n",
       "      <td>4.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>TX</td>\n",
       "      <td>green</td>\n",
       "      <td>Lamb</td>\n",
       "      <td>2</td>\n",
       "      <td>70</td>\n",
       "      <td>8.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aaron</th>\n",
       "      <td>FL</td>\n",
       "      <td>red</td>\n",
       "      <td>Mango</td>\n",
       "      <td>12</td>\n",
       "      <td>120</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>AL</td>\n",
       "      <td>white</td>\n",
       "      <td>Apple</td>\n",
       "      <td>4</td>\n",
       "      <td>80</td>\n",
       "      <td>3.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>AK</td>\n",
       "      <td>gray</td>\n",
       "      <td>Cheese</td>\n",
       "      <td>32</td>\n",
       "      <td>180</td>\n",
       "      <td>1.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christina</th>\n",
       "      <td>TX</td>\n",
       "      <td>black</td>\n",
       "      <td>Melon</td>\n",
       "      <td>33</td>\n",
       "      <td>172</td>\n",
       "      <td>9.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cornelia</th>\n",
       "      <td>TX</td>\n",
       "      <td>red</td>\n",
       "      <td>Beans</td>\n",
       "      <td>69</td>\n",
       "      <td>150</td>\n",
       "      <td>2.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          state  color    food  age  height  score\n",
       "Jane         NY   blue   Steak   30     165    4.6\n",
       "Niko         TX  green    Lamb    2      70    8.3\n",
       "Aaron        FL    red   Mango   12     120    9.0\n",
       "Penelope     AL  white   Apple    4      80    3.3\n",
       "Dean         AK   gray  Cheese   32     180    1.8\n",
       "Christina    TX  black   Melon   33     172    9.5\n",
       "Cornelia     TX    red   Beans   69     150    2.2"
      ]
     },
     "execution_count": 51,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('../../data/sample_data.csv', index_col=0)\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 3\n",
    "<span  style=\"color:green; font-size:16px\">Determine whether the following line of code is chained indexing. If it is, rewrite it so that it is not.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>state</th>\n",
       "      <th>food</th>\n",
       "      <th>color</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Jane</th>\n",
       "      <td>NY</td>\n",
       "      <td>Steak</td>\n",
       "      <td>blue</td>\n",
       "      <td>4.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>TX</td>\n",
       "      <td>Lamb</td>\n",
       "      <td>green</td>\n",
       "      <td>8.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aaron</th>\n",
       "      <td>FL</td>\n",
       "      <td>Mango</td>\n",
       "      <td>red</td>\n",
       "      <td>9.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>AL</td>\n",
       "      <td>Apple</td>\n",
       "      <td>white</td>\n",
       "      <td>3.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>AK</td>\n",
       "      <td>Cheese</td>\n",
       "      <td>gray</td>\n",
       "      <td>1.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christina</th>\n",
       "      <td>TX</td>\n",
       "      <td>Melon</td>\n",
       "      <td>black</td>\n",
       "      <td>9.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cornelia</th>\n",
       "      <td>TX</td>\n",
       "      <td>Beans</td>\n",
       "      <td>red</td>\n",
       "      <td>2.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          state    food  color  score\n",
       "Jane         NY   Steak   blue    4.6\n",
       "Niko         TX    Lamb  green    8.3\n",
       "Aaron        FL   Mango    red    9.0\n",
       "Penelope     AL   Apple  white    3.3\n",
       "Dean         AK  Cheese   gray    1.8\n",
       "Christina    TX   Melon  black    9.5\n",
       "Cornelia     TX   Beans    red    2.2"
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['state', 'food', 'color', 'score']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "No, this is the correct way of choosing several columns - with a list of strings."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 4\n",
    "<span  style=\"color:green; font-size:16px\">Determine whether the following line of code is chained indexing. If it is, rewrite it so that it is not.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>state</th>\n",
       "      <th>food</th>\n",
       "      <th>color</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>TX</td>\n",
       "      <td>Lamb</td>\n",
       "      <td>green</td>\n",
       "      <td>8.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>AL</td>\n",
       "      <td>Apple</td>\n",
       "      <td>white</td>\n",
       "      <td>3.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>AK</td>\n",
       "      <td>Cheese</td>\n",
       "      <td>gray</td>\n",
       "      <td>1.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cornelia</th>\n",
       "      <td>TX</td>\n",
       "      <td>Beans</td>\n",
       "      <td>red</td>\n",
       "      <td>2.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jane</th>\n",
       "      <td>NY</td>\n",
       "      <td>Steak</td>\n",
       "      <td>blue</td>\n",
       "      <td>4.6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         state    food  color  score\n",
       "Niko        TX    Lamb  green    8.3\n",
       "Penelope    AL   Apple  white    3.3\n",
       "Dean        AK  Cheese   gray    1.8\n",
       "Cornelia    TX   Beans    red    2.2\n",
       "Jane        NY   Steak   blue    4.6"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[['Niko', 'Penelope', 'Dean', 'Cornelia', 'Jane'], ['state', 'food', 'color', 'score']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "No, this is the correct way to choose rows and columns. There is exactly one call to **`.loc`**. The row selection is simultaneously done with the column selection."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 5\n",
    "<span  style=\"color:green; font-size:16px\">Determine whether the following line of code is chained indexing. If it is, rewrite it so that it is not.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>state</th>\n",
       "      <th>food</th>\n",
       "      <th>color</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>TX</td>\n",
       "      <td>Lamb</td>\n",
       "      <td>green</td>\n",
       "      <td>8.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>AL</td>\n",
       "      <td>Apple</td>\n",
       "      <td>white</td>\n",
       "      <td>3.3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>AK</td>\n",
       "      <td>Cheese</td>\n",
       "      <td>gray</td>\n",
       "      <td>1.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cornelia</th>\n",
       "      <td>TX</td>\n",
       "      <td>Beans</td>\n",
       "      <td>red</td>\n",
       "      <td>2.2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Jane</th>\n",
       "      <td>NY</td>\n",
       "      <td>Steak</td>\n",
       "      <td>blue</td>\n",
       "      <td>4.6</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         state    food  color  score\n",
       "Niko        TX    Lamb  green    8.3\n",
       "Penelope    AL   Apple  white    3.3\n",
       "Dean        AK  Cheese   gray    1.8\n",
       "Cornelia    TX   Beans    red    2.2\n",
       "Jane        NY   Steak   blue    4.6"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[['Niko', 'Penelope', 'Dean', 'Cornelia', 'Jane']][['state', 'food', 'color', 'score']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is chained indexing. There is one call to **`.loc`** which selects the rows and another call to *just the indexing operator* which selects the columns. The idiomatic solution is the code from exercise 4"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 6\n",
    "<span  style=\"color:green; font-size:16px\">Determine whether the following line of code is chained indexing. If it is, rewrite it so that it is not.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>color</th>\n",
       "      <th>food</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Aaron</th>\n",
       "      <td>red</td>\n",
       "      <td>Mango</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>white</td>\n",
       "      <td>Apple</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>gray</td>\n",
       "      <td>Cheese</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          color    food  age\n",
       "Aaron       red   Mango   12\n",
       "Penelope  white   Apple    4\n",
       "Dean       gray  Cheese   32"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[:5].iloc[2:, 1:4]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is chained indexing. There are two separate calls to **`.iloc`**. Fix it like this:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>color</th>\n",
       "      <th>food</th>\n",
       "      <th>age</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Aaron</th>\n",
       "      <td>red</td>\n",
       "      <td>Mango</td>\n",
       "      <td>12</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>white</td>\n",
       "      <td>Apple</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>gray</td>\n",
       "      <td>Cheese</td>\n",
       "      <td>32</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          color    food  age\n",
       "Aaron       red   Mango   12\n",
       "Penelope  white   Apple    4\n",
       "Dean       gray  Cheese   32"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.iloc[2:5, 1:4]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 7\n",
    "<span  style=\"color:green; font-size:16px\">Determine whether the following line of code is chained indexing. If it is, rewrite it so that it is not.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Niko          2\n",
       "Christina    33\n",
       "Cornelia     69\n",
       "Name: age, dtype: int64"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[df['state'] == 'TX']['age']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is chained indexing. Use **`.loc`** for simultaneous boolean selection and column selection"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Niko          2\n",
       "Christina    33\n",
       "Cornelia     69\n",
       "Name: age, dtype: int64"
      ]
     },
     "execution_count": 58,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[df['state'] == 'TX', 'age']"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 8\n",
    "<span  style=\"color:green; font-size:16px\">Determine whether the following line of code is chained indexing. If it is, rewrite it so that it is not.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>age</th>\n",
       "      <th>state</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Jane</th>\n",
       "      <td>30</td>\n",
       "      <td>NY</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aaron</th>\n",
       "      <td>12</td>\n",
       "      <td>FL</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       age state\n",
       "Jane    30    NY\n",
       "Aaron   12    FL"
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df[['state', 'food', 'age', 'height']][['state', 'age']].loc[['Jane', 'Aaron'], ['age', 'state']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This has three chains!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>age</th>\n",
       "      <th>state</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Jane</th>\n",
       "      <td>30</td>\n",
       "      <td>NY</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aaron</th>\n",
       "      <td>12</td>\n",
       "      <td>FL</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       age state\n",
       "Jane    30    NY\n",
       "Aaron   12    FL"
      ]
     },
     "execution_count": 60,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[['Jane', 'Aaron'], ['age', 'state']]"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 9\n",
    "<span  style=\"color:green; font-size:16px\">Change the score for all people who are over 30 years of age to 99 without doing chained indexing</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>state</th>\n",
       "      <th>color</th>\n",
       "      <th>food</th>\n",
       "      <th>age</th>\n",
       "      <th>height</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Jane</th>\n",
       "      <td>NY</td>\n",
       "      <td>blue</td>\n",
       "      <td>Steak</td>\n",
       "      <td>30</td>\n",
       "      <td>165</td>\n",
       "      <td>4.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>TX</td>\n",
       "      <td>green</td>\n",
       "      <td>Lamb</td>\n",
       "      <td>2</td>\n",
       "      <td>70</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aaron</th>\n",
       "      <td>FL</td>\n",
       "      <td>red</td>\n",
       "      <td>Mango</td>\n",
       "      <td>12</td>\n",
       "      <td>120</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>AL</td>\n",
       "      <td>white</td>\n",
       "      <td>Apple</td>\n",
       "      <td>4</td>\n",
       "      <td>80</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>AK</td>\n",
       "      <td>gray</td>\n",
       "      <td>Cheese</td>\n",
       "      <td>32</td>\n",
       "      <td>180</td>\n",
       "      <td>1.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christina</th>\n",
       "      <td>TX</td>\n",
       "      <td>black</td>\n",
       "      <td>Melon</td>\n",
       "      <td>33</td>\n",
       "      <td>172</td>\n",
       "      <td>9.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cornelia</th>\n",
       "      <td>TX</td>\n",
       "      <td>red</td>\n",
       "      <td>Beans</td>\n",
       "      <td>69</td>\n",
       "      <td>150</td>\n",
       "      <td>2.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          state  color    food  age  height  score\n",
       "Jane         NY   blue   Steak   30     165    4.6\n",
       "Niko         TX  green    Lamb    2      70   99.0\n",
       "Aaron        FL    red   Mango   12     120   99.0\n",
       "Penelope     AL  white   Apple    4      80   99.0\n",
       "Dean         AK   gray  Cheese   32     180    1.8\n",
       "Christina    TX  black   Melon   33     172    9.5\n",
       "Cornelia     TX    red   Beans   69     150    2.2"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc[df['age'] < 30, 'score'] = 99\n",
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 10\n",
    "<span  style=\"color:green; font-size:16px\">Select the **`color`** and **`food`** columns into their own variable.  Then write one more line of code that will trigger the **`SettingWithCopy`** warning</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>color</th>\n",
       "      <th>food</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Jane</th>\n",
       "      <td>blue</td>\n",
       "      <td>Steak</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>green</td>\n",
       "      <td>Lamb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aaron</th>\n",
       "      <td>red</td>\n",
       "      <td>Mango</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>white</td>\n",
       "      <td>Apple</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>gray</td>\n",
       "      <td>Cheese</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christina</th>\n",
       "      <td>black</td>\n",
       "      <td>Melon</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cornelia</th>\n",
       "      <td>red</td>\n",
       "      <td>Beans</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           color    food\n",
       "Jane        blue   Steak\n",
       "Niko       green    Lamb\n",
       "Aaron        red   Mango\n",
       "Penelope   white   Apple\n",
       "Dean        gray  Cheese\n",
       "Christina  black   Melon\n",
       "Cornelia     red   Beans"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = df[['color', 'food']]\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/Ted/anaconda3/lib/python3.6/site-packages/pandas/core/indexing.py:194: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  self._setitem_with_indexer(indexer, value)\n",
      "/Users/Ted/anaconda3/lib/python3.6/site-packages/ipykernel_launcher.py:1: SettingWithCopyWarning: \n",
      "A value is trying to be set on a copy of a slice from a DataFrame\n",
      "\n",
      "See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy\n",
      "  \"\"\"Entry point for launching an IPython kernel.\n"
     ]
    }
   ],
   "source": [
    "df1.loc[df['color'] == 'red', 'food'] = ['Watermelon', 'Gyros']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>color</th>\n",
       "      <th>food</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Jane</th>\n",
       "      <td>blue</td>\n",
       "      <td>Steak</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>green</td>\n",
       "      <td>Lamb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aaron</th>\n",
       "      <td>red</td>\n",
       "      <td>Watermelon</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>white</td>\n",
       "      <td>Apple</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>gray</td>\n",
       "      <td>Cheese</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christina</th>\n",
       "      <td>black</td>\n",
       "      <td>Melon</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cornelia</th>\n",
       "      <td>red</td>\n",
       "      <td>Gyros</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           color        food\n",
       "Jane        blue       Steak\n",
       "Niko       green        Lamb\n",
       "Aaron        red  Watermelon\n",
       "Penelope   white       Apple\n",
       "Dean        gray      Cheese\n",
       "Christina  black       Melon\n",
       "Cornelia     red       Gyros"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 11\n",
    "<span  style=\"color:green; font-size:16px\">Select the **`color`** and **`food`** columns into their own variable like you did in exercise 10.  Do the same operation as you did without getting the warning.</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>color</th>\n",
       "      <th>food</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Jane</th>\n",
       "      <td>blue</td>\n",
       "      <td>Steak</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>green</td>\n",
       "      <td>Lamb</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aaron</th>\n",
       "      <td>red</td>\n",
       "      <td>Watermelon</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>white</td>\n",
       "      <td>Apple</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>gray</td>\n",
       "      <td>Cheese</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christina</th>\n",
       "      <td>black</td>\n",
       "      <td>Melon</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cornelia</th>\n",
       "      <td>red</td>\n",
       "      <td>Gyros</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "           color        food\n",
       "Jane        blue       Steak\n",
       "Niko       green        Lamb\n",
       "Aaron        red  Watermelon\n",
       "Penelope   white       Apple\n",
       "Dean        gray      Cheese\n",
       "Christina  black       Melon\n",
       "Cornelia     red       Gyros"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df1 = df[['color', 'food']].copy()\n",
    "df1.loc[df['color'] == 'red', 'food'] = ['Watermelon', 'Gyros']\n",
    "df1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>state</th>\n",
       "      <th>color</th>\n",
       "      <th>food</th>\n",
       "      <th>age</th>\n",
       "      <th>height</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Jane</th>\n",
       "      <td>NY</td>\n",
       "      <td>blue</td>\n",
       "      <td>Steak</td>\n",
       "      <td>30</td>\n",
       "      <td>165</td>\n",
       "      <td>4.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>TX</td>\n",
       "      <td>green</td>\n",
       "      <td>Lamb</td>\n",
       "      <td>2</td>\n",
       "      <td>70</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aaron</th>\n",
       "      <td>FL</td>\n",
       "      <td>red</td>\n",
       "      <td>Mango</td>\n",
       "      <td>12</td>\n",
       "      <td>120</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>AL</td>\n",
       "      <td>white</td>\n",
       "      <td>Apple</td>\n",
       "      <td>4</td>\n",
       "      <td>80</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>AK</td>\n",
       "      <td>gray</td>\n",
       "      <td>Cheese</td>\n",
       "      <td>32</td>\n",
       "      <td>180</td>\n",
       "      <td>1.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christina</th>\n",
       "      <td>TX</td>\n",
       "      <td>black</td>\n",
       "      <td>Melon</td>\n",
       "      <td>33</td>\n",
       "      <td>172</td>\n",
       "      <td>9.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cornelia</th>\n",
       "      <td>TX</td>\n",
       "      <td>red</td>\n",
       "      <td>Beans</td>\n",
       "      <td>69</td>\n",
       "      <td>150</td>\n",
       "      <td>2.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          state  color    food  age  height  score\n",
       "Jane         NY   blue   Steak   30     165    4.6\n",
       "Niko         TX  green    Lamb    2      70   99.0\n",
       "Aaron        FL    red   Mango   12     120   99.0\n",
       "Penelope     AL  white   Apple    4      80   99.0\n",
       "Dean         AK   gray  Cheese   32     180    1.8\n",
       "Christina    TX  black   Melon   33     172    9.5\n",
       "Cornelia     TX    red   Beans   69     150    2.2"
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Exercise 12\n",
    "<span  style=\"color:green; font-size:16px\">Change the values of **`color`**, **`age`**, and **`score`** for **`Niko`** to anything you like</span>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>state</th>\n",
       "      <th>color</th>\n",
       "      <th>food</th>\n",
       "      <th>age</th>\n",
       "      <th>height</th>\n",
       "      <th>score</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Jane</th>\n",
       "      <td>NY</td>\n",
       "      <td>blue</td>\n",
       "      <td>Steak</td>\n",
       "      <td>30</td>\n",
       "      <td>165</td>\n",
       "      <td>4.6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Niko</th>\n",
       "      <td>TX</td>\n",
       "      <td>RED</td>\n",
       "      <td>Lamb</td>\n",
       "      <td>999</td>\n",
       "      <td>70</td>\n",
       "      <td>-1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Aaron</th>\n",
       "      <td>FL</td>\n",
       "      <td>red</td>\n",
       "      <td>Mango</td>\n",
       "      <td>12</td>\n",
       "      <td>120</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Penelope</th>\n",
       "      <td>AL</td>\n",
       "      <td>white</td>\n",
       "      <td>Apple</td>\n",
       "      <td>4</td>\n",
       "      <td>80</td>\n",
       "      <td>99.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Dean</th>\n",
       "      <td>AK</td>\n",
       "      <td>gray</td>\n",
       "      <td>Cheese</td>\n",
       "      <td>32</td>\n",
       "      <td>180</td>\n",
       "      <td>1.8</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Christina</th>\n",
       "      <td>TX</td>\n",
       "      <td>black</td>\n",
       "      <td>Melon</td>\n",
       "      <td>33</td>\n",
       "      <td>172</td>\n",
       "      <td>9.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Cornelia</th>\n",
       "      <td>TX</td>\n",
       "      <td>red</td>\n",
       "      <td>Beans</td>\n",
       "      <td>69</td>\n",
       "      <td>150</td>\n",
       "      <td>2.2</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          state  color    food  age  height  score\n",
       "Jane         NY   blue   Steak   30     165    4.6\n",
       "Niko         TX    RED    Lamb  999      70   -1.0\n",
       "Aaron        FL    red   Mango   12     120   99.0\n",
       "Penelope     AL  white   Apple    4      80   99.0\n",
       "Dean         AK   gray  Cheese   32     180    1.8\n",
       "Christina    TX  black   Melon   33     172    9.5\n",
       "Cornelia     TX    red   Beans   69     150    2.2"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.loc['Niko', ['color', 'age', 'score']] = ['RED', 999, -1]\n",
    "df"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
